BITFALL/Assets/BITKit/UnityPluginsSupport/MonkeyCommand/InstanceMaterial.cs

26 lines
928 B
C#
Raw Normal View History

2023-08-12 01:43:24 +08:00
using System.Collections;
// ReSharper disable RedundantUsingDirective
using System.Collections.Generic;
// ReSharper restore RedundantUsingDirective
using MonKey;
using UnityEditor;
using UnityEngine;
2023-10-20 19:31:12 +08:00
using Selection = UnityEditor.Selection;
2023-08-12 01:43:24 +08:00
namespace BITKit
{
2023-10-20 19:31:12 +08:00
public partial class BITMonkeyCommands
2023-08-12 01:43:24 +08:00
{
[Command(nameof(InstanceRendererMaterial), "Instance Material From Selected GameObject", QuickName = "ins"), MenuItem("Tools/Instance Material")]
2023-10-20 19:31:12 +08:00
private static void InstanceRendererMaterial()
2023-08-12 01:43:24 +08:00
{
2023-10-20 19:31:12 +08:00
if (UnityEditor.Selection.activeTransform is null) return;
if (UnityEditor.Selection.activeTransform.TryGetComponent<Renderer>(out var renderer))
2023-08-12 01:43:24 +08:00
{
renderer.sharedMaterial = Object.Instantiate(renderer.material);
}
2023-10-20 19:31:12 +08:00
EditorUtility.SetDirty(UnityEditor.Selection.activeTransform.GetComponent<Renderer>());
2023-08-12 01:43:24 +08:00
}
}
}