2026-03-10 10:01:38 +01:00

51 lines
1.3 KiB
C#

using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace Passer.CreatureControl {
[CustomEditor(typeof(Creature), true)]
public class Creature_Editor : Editor {
protected Creature creature;
#region Init
public virtual void OnEnable() {
creature = target as Creature;
bool anythingChanged = false;
if (!IsPrefab(creature)) {
anythingChanged |= creature.CheckTargetRig();
anythingChanged |= creature.CheckModel();
}
creature.targetRig.MatchTo(creature, ref anythingChanged);
if (anythingChanged) {
EditorUtility.SetDirty(creature);
AssetDatabase.SaveAssets();
}
}
public static bool IsPrefab(Creature creature) {
PrefabStage prefabStage = PrefabStageUtility.GetPrefabStage(creature.gameObject);
return prefabStage != null;
}
#endregion Init
#region Scene
public virtual void OnSceneGUI() {
if (Application.isPlaying || creature.enabled == false)
return;
creature.Update();
}
#endregion Scene
}
}