public static void TurnIntoProxy(WorldStampDataContainer wsdc)
        {
            if (!EditorUtility.DisplayDialog("Are you sure?",
                                             "This will delete any instance data you changed on this object.", "Yes", "No"))
            {
                return;
            }

#if UNITY_2018_2_OR_NEWER
            var prefabParent = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(wsdc.transform.parent.gameObject);
#else
            var prefabParent = UnityEditor.PrefabUtility.GetPrefabParent(wsdc.transform.parent.gameObject);
#endif
            if (prefabParent == null)
            {
                Debug.LogError("Unable to find prefab");
                return;
            }
            var prefabGo = prefabParent as GameObject;
            if (prefabGo == null)
            {
                Debug.LogError("Unable to find prefab");
                return;
            }
            var prefabWsdc = prefabGo.GetComponentInChildren <WorldStampDataContainer>();
            if (prefabWsdc == null)
            {
                Debug.LogError("Unable to find data container on prefab");
                return;
            }
            if (wsdc.Redirect != prefabWsdc)
            {
                wsdc.Redirect = prefabWsdc;
                if (WorldStampDataContainer.Ignores.Contains(wsdc.Data))
                {
                    WorldStampDataContainer.Ignores.Remove(wsdc.Data);
                    prefabWsdc.Data = wsdc.Data.JSONClone();
                }
            }
#if HURTWORLDSDK
            if (wsdc.Redirect != null && !ReferenceEquals(wsdc.Redirect.Data, wsdc.Data))
            {
                //Debug.Log("Set instance data to null, but this should be fine.", wsdc);
                wsdc.Data = null;
            }
#endif
        }
Example #2
0
        public void LinkToPrefab()
        {
#if UNITY_EDITOR
#if UNITY_2018_2_OR_NEWER
            var prefabParent = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(transform.parent.gameObject);
#else
            var prefabParent = UnityEditor.PrefabUtility.GetPrefabParent(transform.parent.gameObject);
#endif
            if (prefabParent == null)
            {
                //Debug.LogError("Unable to find prefab");
                return;
            }
            var prefabGo = prefabParent as GameObject;
            if (prefabGo == null)
            {
                Debug.LogError("Unable to find prefab");
                return;
            }
            var prefabWsdc = prefabGo.GetComponentInChildren <WorldStampDataContainer>();
            if (prefabWsdc == null)
            {
                Debug.LogError("Unable to find data container on prefab");
                return;
            }
            if (Redirect == null || Redirect.Data != prefabWsdc.Data)
            {
                Redirect = prefabWsdc;
                if (Ignores.Contains(Data))
                {
                    Ignores.Remove(Data);
                    prefabWsdc.Data = Data.JSONClone();
                }
#if HURTWORLDSDK
                if (!ReferenceEquals(Data, prefabWsdc.Data))
                {
                    //Debug.Log("Set data to null but this should be fine.");
                    Data = null;
                }
#endif
            }
#endif
        }
 public static void TurnIntoInstance(WorldStampDataContainer wsdc)
 {
     wsdc.Data     = JsonUtility.FromJson <WorldStampData>(JsonUtility.ToJson(wsdc.Redirect.Data));
     wsdc.Redirect = null;
 }