virtual protected void OnCreatedInEditor() { // Set my Room ref! MyRoom = GetComponentInParent <Room>(); if (MyRoom == null) { MyRoom = FindObjectOfType <Room>(); } // Also check the whole scene, just in case. // Parent me. this.transform.SetParent(MyRoom.transform); // Unpack me as a Prefab! if (UnityEditor.PrefabUtility.IsPartOfAnyPrefab(this.gameObject)) { UnityEditor.PrefabUtility.UnpackPrefabInstance(this.gameObject, UnityEditor.PrefabUnpackMode.Completely, UnityEditor.InteractionMode.AutomatedAction); } // Set component references! if (travelMind == null) { travelMind = GetComponent <PropTravelMind>(); if (travelMind != null) // I DO have a TravelMind? Initialize it as we would've normally. { travelMind.Initialize(new TravelMindData(travelMind)); } } }
public void RemoveTravelMind() { if (travelMind == null) { return; } // Safety check. Destroy(travelMind); travelMind = null; EnableSnappingScript(); }
public void AddTravelMind(TravelMindData data) { if (travelMind != null) { return; } // Safety check. travelMind = gameObject.AddComponent <PropTravelMind>(); travelMind.Initialize(data); DisableSnappingScript(); }
public TravelMindData(PropTravelMind script) { if (script != null) { posA = script.PosA; posB = script.PosB; speed = script.Speed; locOffset = script.LocOffset; } else { posA = new Vector2(0, 0); posB = new Vector2(0, 0); speed = 1; locOffset = 0; } }