Пример #1
0
        void Awake()
        {
            if (Components == null || Components.Length <= 0)
            {
                PreLoadingComponents();
            }

            var components = new List <object>();

            if (Components != null && Components.Length > 0)
            {
                for (int i = 0; i < Components.Length; i++)
                {
                    if (Components[i] == null)
                    {
#if UNITY_EDITOR
                        Debug.LogError(string.Format("Component on {0} is missing! [{1}]", this.gameObject.name, i));
#endif
                        continue;
                    }
                    components.Add(Components[i]);
                }
            }
            var runtimeComponents = new List <object>();
            if (RuntimeComponents != null && RuntimeComponents.Count > 0)
            {
                for (int i = 0; i < RuntimeComponents.Count; i++)
                {
                    if (RuntimeComponents[i] == null)
                    {
#if UNITY_EDITOR
                        Debug.LogError(string.Format("Runtime Component on {0} is missing! [{1}]", this.gameObject.name, i));
#endif
                        continue;
                    }
                    runtimeComponents.Add(RuntimeObject.FromJson(RuntimeComponents[i]));
                }
            }
            components.Add(AddViewComponent(runtimeComponents));
            components.AddRange(runtimeComponents);

            if (ScriptableComponents != null && ScriptableComponents.Count > 0)
            {
                for (int i = 0; i < ScriptableComponents.Count; i++)
                {
                    if (ScriptableComponents[i] == null)
                    {
#if UNITY_EDITOR
                        Debug.LogError(string.Format("Scriptable Component on {0} is missing! [{1}]", this.gameObject.name, i));
#endif
                        continue;
                    }
                    components.Add(ScriptableComponents[i]);
                }
            }
            Entity.AddComponents(components.ToArray());
        }
Пример #2
0
        public static object GetRuntimeObject(RuntimeSerializedProperty property, string json)
        {
            var hashCode = property.HashCodeForPropertyPath();

            if (!RuntimeObjectDict.ContainsKey(hashCode))
            {
                RuntimeObjectDict.Add(hashCode, RuntimeObject.FromJson(json));
            }

            return(RuntimeObjectDict[hashCode]);
        }
    private void PublishEvents(Object source, List <string> events, List <ComponentReference> references = null)
    {
        foreach (var evt in events)
        {
            var message           = RuntimeObject.FromJson(evt);
            var serializableEvent = message as ISerializableEvent;

            serializableEvent.Source     = source;
            serializableEvent.References = references;
            EventSystem.Send(message);
        }
    }
Пример #4
0
        public static void RevertPrefabPropertyOverride(object userData)
        {
            RuntimeSerializedProperty runtimeSerializedProperty = userData as RuntimeSerializedProperty;
            SerializedProperty        serializedProperty        = runtimeSerializedProperty.RuntimeSerializedObject.ParentProperty as SerializedProperty;

            if (serializedProperty == null)
            {
                Debug.LogError("Revert Value to Prefab is not supported on Nested Runtime Serialized Property!");
                return;
            }
            int index;
            var parentProperty = serializedProperty.GetBelongArrayAndIndex(out index);

            if (index >= 0)
            {
#if UNITY_2018_2_OR_NEWER
                Object prefab = PrefabUtility.GetCorrespondingObjectFromSource(parentProperty.serializedObject.targetObject);
#else
                Object prefab = PrefabUtility.GetPrefabParent(parentProperty.serializedObject.targetObject);
#endif
                SerializedObject   serializedObject = new SerializedObject(prefab);
                SerializedProperty prop             = serializedObject.FindProperty(parentProperty.propertyPath);

                parentProperty.arraySize = prop.arraySize;
                for (int i = 0; i < parentProperty.arraySize; i++)
                {
                    var obj1 = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(parentProperty.GetArrayElementAtIndex(i));
                    var obj2 = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(prop.GetArrayElementAtIndex(i), RuntimeObject.FromJson(prop.GetArrayElementAtIndex(i).stringValue));
                    obj1.Target = obj2.Target;
                    obj1.ForceReloadProperties();
                }

                EditorUtilityHelper.ForceReloadInspectors();
            }
        }
        public static void RevertPrefabPropertyOverride(object userData)
        {
            SerializedProperty parentProperty = userData as SerializedProperty;

#if UNITY_2018_2_OR_NEWER
            Object prefab = PrefabUtility.GetCorrespondingObjectFromSource(parentProperty.serializedObject.targetObject);
#else
            Object prefab = PrefabUtility.GetPrefabParent(parentProperty.serializedObject.targetObject);
#endif
            SerializedObject   serializedObject = new SerializedObject(prefab);
            SerializedProperty prop             = serializedObject.FindProperty(parentProperty.propertyPath);

            parentProperty.arraySize = prop.arraySize;
            for (int i = 0; i < parentProperty.arraySize; i++)
            {
                var obj1 = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(parentProperty.GetArrayElementAtIndex(i));
                var obj2 = RuntimeSerializedObjectCache.GetRuntimeSerializedObject(prop.GetArrayElementAtIndex(i), RuntimeObject.FromJson(prop.GetArrayElementAtIndex(i).stringValue));
                obj1.Target = obj2.Target;
                obj1.ForceReloadProperties();
            }

            EditorUtilityHelper.ForceReloadInspectors();
        }