54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
|
|
namespace Passer.CreatureControl {
|
|
|
|
[CustomEditor(typeof(Creature), true)]
|
|
public class Creature_Editor : Editor {
|
|
|
|
/// <summary>
|
|
/// The creature managed by this editor
|
|
/// </summary>
|
|
protected Creature creature;
|
|
|
|
#region Start
|
|
|
|
/// <summary>
|
|
/// Enable the creature editor
|
|
/// </summary>
|
|
public virtual void OnEnable() {
|
|
this.creature = target as Creature;
|
|
|
|
// Keep track if anything changed while enabling the creature editor
|
|
bool anythingChanged = false;
|
|
|
|
if (IsPrefab(this.creature) == false) {
|
|
// Only do this when it is not a prefab
|
|
anythingChanged |= this.creature.CheckTargetRig();
|
|
anythingChanged |= this.creature.CheckModel();
|
|
}
|
|
|
|
this.creature.targetRig.MatchTo(this.creature, ref anythingChanged);
|
|
|
|
// As the above functions do not use the serialized object
|
|
// We need to manually persist the changes.
|
|
if (anythingChanged) {
|
|
EditorUtility.SetDirty(this.creature);
|
|
AssetDatabase.SaveAssets();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if the given creature is a prefab
|
|
/// </summary>
|
|
/// <param name="creature">The creature to check</param>
|
|
/// <returns>True when it is a prefab</returns>
|
|
public static bool IsPrefab(Creature creature) {
|
|
PrefabStage prefabStage = PrefabStageUtility.GetPrefabStage(creature.gameObject);
|
|
return prefabStage != null;
|
|
}
|
|
|
|
#endregion Start
|
|
|
|
}
|
|
} |