public IEnumerator GuidPrefab() { Assert.AreNotEqual(guidBase.GetGuid(), guidPrefab.GetGuid()); Assert.AreEqual(guidPrefab.GetGuid(), System.Guid.Empty); yield return(null); }
public void GetGuid_ReturnsUniqueGuid_WhenInstantiatedFromPrefab() { GuidComponent instance = Object.Instantiate <GuidComponent>(guidPrefab); Assert.AreNotEqual(guidBase.GetGuid(), instance.GetGuid()); Assert.AreNotEqual(instance.GetGuid(), guidPrefab.GetGuid()); }
public void GetGuid_ReturnsUniqueGuid_WhenInstantiatedFromGameObject() { LogAssert.Expect(LogType.Warning, "Guid Collision Detected while creating GuidTestGO(Clone).\nAssigning new Guid."); GuidComponent clone = Object.Instantiate <GuidComponent>(guidBase); Assert.AreNotEqual(guidBase.GetGuid(), clone.GetGuid()); }
public IEnumerator GuidPrefabInstance() { GuidComponent instance = GameObject.Instantiate <GuidComponent>(guidPrefab); Assert.AreNotEqual(guidBase.GetGuid(), instance.GetGuid()); Assert.AreNotEqual(instance.GetGuid(), guidPrefab.GetGuid()); yield return(null); }
public IEnumerator GuidDuplication() { LogAssert.Expect(LogType.Warning, "Guid Collision Detected while creating GuidTestGO(Clone).\nAssigning new Guid."); GuidComponent clone = GameObject.Instantiate <GuidComponent>(guidBase); Assert.AreNotEqual(guidBase.GetGuid(), clone.GetGuid()); yield return(null); }
public void GetGuid_ReturnsUniqueGuid_WhenNewGameObjectCreated() { GuidComponent guid1 = guidBase; GuidComponent guid2 = CreateNewGuid(); Assert.AreNotEqual(guid1.GetGuid(), guid2.GetGuid()); }
private bool InternalAdd(GuidComponent guidComponent) { Guid guid = guidComponent.GetGuid(); GuidManager.GuidInfo guidInfo = new GuidManager.GuidInfo(guidComponent); if (!this.guidToObjectMap.ContainsKey(guid)) { this.guidToObjectMap.Add(guid, guidInfo); return(true); } GuidManager.GuidInfo guidInfo2 = this.guidToObjectMap[guid]; if (guidInfo2.go != null && guidInfo2.go != guidComponent.gameObject) { if (Application.isPlaying) { Debug.LogWarningFormat("Guid Collision Detected between {0} and {1}.\nAssigning new Guid. Consider tracking runtime instances using a direct reference or other method.", new object[] { (this.guidToObjectMap[guid].go != null) ? this.guidToObjectMap[guid].go.name : "NULL", (guidComponent != null) ? guidComponent.name : "NULL" }); } else { Debug.LogWarningFormat(guidComponent, "Guid Collision Detected while creating {0}.\nAssigning new Guid.", new object[] { (guidComponent != null) ? guidComponent.name : "NULL" }); } return(false); } guidInfo2.go = guidInfo.go; guidInfo2.HandleAddCallback(); this.guidToObjectMap[guid] = guidInfo2; return(true); }
protected override void FinishObjectSave() { if (currentGuidComponent == null) { throw new NullReferenceException("Guid is null"); } Debug.Log(GetSavePath(currentGuidComponent.GetGuid())); using (var file = File.CreateText(GetSavePath(currentGuidComponent.GetGuid()))) using (var writer = new JsonTextWriter(file)) { writer.Formatting = Formatting.Indented; openJObject.WriteTo(writer); } }
public void GuidReference_ReturnsGameObject_WhenValidReference() { GuidComponent newGuid = GuidComponentTests.CreateNewGuid(); GuidReference reference = new GuidReference(newGuid.GetGuid()); guidManagerMock.ResolveGuidResult = newGuid.gameObject; Assert.AreEqual(newGuid.gameObject, reference.gameObject); }
public IEnumerator GuidCreation() { GuidComponent guid1 = guidBase; GuidComponent guid2 = CreateNewGuid(); Assert.AreNotEqual(guid1.GetGuid(), guid2.GetGuid()); yield return(null); }
public override int GetHashCode() { if (GuidComponent == null) { throw new NullReferenceException("Saved object expected the game object to have a GUID Component"); } return(BitConverter.ToInt32(GuidComponent.GetGuid().ToByteArray(), 0)); }
public void GuidReference_ReturnsNull_WhenTargetGameObjectDestroyed() { GuidComponent newGuid = GuidComponentTests.CreateNewGuid(); GuidReference reference = new GuidReference(newGuid.GetGuid()); // todo Object.DestroyImmediate(newGuid); Assert.IsNull(reference.gameObject); }
public override void OnInspectorGUI() { if (guidComp == null) { guidComp = (GuidComponent)target; } // Draw label EditorGUILayout.LabelField("Guid:", guidComp.GetGuid().ToString()); }
// Start is called before the first frame update void Start() { GameObject main = GameObject.Find("BattleSetup"); gc = GetComponent <GuidComponent>(); if (main != null) { sr = main.GetComponent <SetupRouter>(); if (sr.battleSetup.GuidInList(gc.GetGuid())) { Destroy(gameObject); } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (guidComp == null) { guidComp = (GuidComponent)target; } // Draw label EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); GUI.enabled = false; EditorGUILayout.LabelField("Guid", guidComp.GetGuid().ToString(), EditorStyles.miniLabel); GUI.enabled = true; }
//------------------------------------------------------------------------- // Unity API //------------------------------------------------------------------------- private void Awake() { GuidComponent guidComponent = gameObject.GetComponent <GuidComponent>(); if (guidComponent != null) { guid = guidComponent.GetGuid().ToString(); if (VSave.Get <bool>(StaticFolders.DESTRUCTIBLE, guid + Keys.KEEP_DESTROYED)) { Destroy(this.gameObject, Delay); } } else { Debug.LogWarning("SelfDestructing object \"" + gameObject.name + "\" needs a GuidComponent!"); } }
private bool InternalAdd(GuidComponent guidComponent) { Guid guid = guidComponent.GetGuid(); GuidInfo info = new GuidInfo(guidComponent); if (!guidToObjectMap.ContainsKey(guid)) { guidToObjectMap.Add(guid, info); return(true); } GuidInfo existingInfo = guidToObjectMap[guid]; if (existingInfo.go != null && existingInfo.go != guidComponent.gameObject) { // normally, a duplicate GUID is a big problem, means you won't necessarily be referencing what you expect if (Application.isPlaying) { Debug.AssertFormat(false, guidComponent, "Guid Collision Detected between {0} and {1}.\nAssigning new Guid. Consider tracking runtime instances using a direct reference or other method.", (guidToObjectMap[guid].go != null ? guidToObjectMap[guid].go.name : "NULL"), (guidComponent != null ? guidComponent.name : "NULL")); } else { // however, at editor time, copying an object with a GUID will duplicate the GUID resulting in a collision and repair. // we warn about this just for pedantry reasons, and so you can detect if you are unexpectedly copying these components Debug.LogWarningFormat(guidComponent, "Guid Collision Detected while creating {0}.\nAssigning new Guid.", (guidComponent != null ? guidComponent.name : "NULL")); } return(false); } // if we already tried to find this GUID, but haven't set the game object to anything specific, copy any OnAdd callbacks then call them existingInfo.go = info.go; existingInfo.HandleAddCallback(); guidToObjectMap[guid] = existingInfo; return(true); }
public GateReference(GuidComponent target) { _guid = target.GetGuid(); }
/// <summary> /// Writes the Component to PersistentData using the Decompose method to create an array of objects /// </summary> public void Write() { PersistentData.Put(_guid.GetGuid(), typeof(T), Decompose(Component)); }
protected override bool DoesSaveExist(GuidComponent guidComponent) { return(File.Exists(JsonDiskSaveProvider.GetSavePath(guidComponent.GetGuid()))); }
public GuidReference(GuidComponent target) { this.guid = target.GetGuid(); }
public void SetParent(GameObject targetWhiteboard) { GuidComponent guidComponent = targetWhiteboard.GetComponent <GuidComponent>(); m_PhotonView.RPC("SetParentRPC", RpcTarget.AllBuffered, guidComponent.GetGuid().ToString()); }
public override void OnInspectorGUI() { if (_guid == null) { _guid = (GuidComponent)target; } using (new EditorGUI.DisabledScope(true)) EditorGUILayout.TextField("Guid:", _guid.GetGuid().ToString()); }
public void GetGuid_ReturnsEmptyGuid_WhenItIsPrefab() { Assert.AreNotEqual(guidBase.GetGuid(), guidPrefab.GetGuid()); Assert.AreEqual(guidPrefab.GetGuid(), System.Guid.Empty); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { guidProp = property.FindPropertyRelative("serializedGuid"); nameProp = property.FindPropertyRelative("cachedName"); sceneProp = property.FindPropertyRelative("cachedScene"); // Using BeginProperty / EndProperty on the parent property means that // prefab override logic works on the entire property. EditorGUI.BeginProperty(position, label, property); position.height = EditorGUIUtility.singleLineHeight; // Draw prefix label, returning the new rect we can draw in var guidCompPosition = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); System.Guid currentGuid; GameObject currentGO = null; // working with array properties is a bit unwieldy // you have to get the property at each index manually byte[] byteArray = new byte[16]; int arraySize = guidProp.arraySize; for (int i = 0; i < arraySize; ++i) { var byteProp = guidProp.GetArrayElementAtIndex(i); byteArray[i] = (byte)byteProp.intValue; } currentGuid = new System.Guid(byteArray); currentGO = GuidManagerSingleton.ResolveGuid(currentGuid); GuidComponent currentGuidComponent = currentGO != null?currentGO.GetComponent <GuidComponent>() : null; GuidComponent component = null; if (currentGuid != System.Guid.Empty && currentGuidComponent == null) { // if our reference is set, but the target isn't loaded, we display the target and the scene it is in, and provide a way to clear the reference float buttonWidth = 55.0f; guidCompPosition.xMax -= buttonWidth; bool guiEnabled = GUI.enabled; GUI.enabled = false; EditorGUI.LabelField(guidCompPosition, new GUIContent(nameProp.stringValue, "Target GameObject is not currently loaded."), EditorStyles.objectField); GUI.enabled = guiEnabled; Rect clearButtonRect = new Rect(guidCompPosition); clearButtonRect.xMin = guidCompPosition.xMax; clearButtonRect.xMax += buttonWidth; if (GUI.Button(clearButtonRect, clearButtonGUI, EditorStyles.miniButton)) { ClearPreviousGuid(); } } else { // if our object is loaded, we can simply use an object field directly component = EditorGUI.ObjectField(guidCompPosition, currentGuidComponent, typeof(GuidComponent), true) as GuidComponent; } if (currentGuidComponent != null && component == null) { ClearPreviousGuid(); } // if we have a valid reference, draw the scene name of the scene it lives in so users can find it if (component != null) { nameProp.stringValue = component.name; string scenePath = component.gameObject.scene.path; sceneProp.objectReferenceValue = AssetDatabase.LoadAssetAtPath <SceneAsset>(scenePath); // only update the GUID Prop if something changed. This fixes multi-edit on GUID References if (component != currentGuidComponent) { byteArray = component.GetGuid().ToByteArray(); arraySize = guidProp.arraySize; for (int i = 0; i < arraySize; ++i) { var byteProp = guidProp.GetArrayElementAtIndex(i); byteProp.intValue = byteArray[i]; } } } EditorGUI.indentLevel++; position.y += EditorGUIUtility.singleLineHeight; bool cachedGUIState = GUI.enabled; GUI.enabled = false; EditorGUI.ObjectField(position, sceneLabel, sceneProp.objectReferenceValue, typeof(SceneAsset), false); GUI.enabled = cachedGUIState; EditorGUI.indentLevel--; EditorGUI.EndProperty(); }