void CacheProperty(SerializedObject obj)
        {
            allTreeViewWrappers.Clear();
            var    prop = obj.GetIterator().Copy();
            string key  = "";

            if (obj.targetObject as Component == null)
            {
                key = "UnityEngine.GameObject";
            }
            else
            {
                key = obj.targetObject.GetType().Name;
            }
            List <TreeViewWrapper> slist;

            if (!serializedPropertys.TryGetValue(key, out slist))
            {
                slist = new List <TreeViewWrapper>();
                serializedPropertys.Add(key, slist);
            }

            TreeViewWrapper temp;

            //GameObject Hack m_IsActive is not a Visable Property but we still want to modify it.
            if (key == "UnityEngine.GameObject")
            {
                var active = obj.FindProperty("m_IsActive");
                if (active != null)
                {
                    temp        = new TreeViewWrapper(Id);
                    temp.values = active.Copy();
                    slist.Add(temp);
                    allTreeViewWrappers.Add(temp);
                    Id++;
                }
            }

            prop.NextVisible(true);
            do
            {
                //排除不希望被修改的欄位
                if (VS_EditorUtility.IsPropertyNeedIgnore(prop))
                {
                    continue;
                }
                temp = new TreeViewWrapper(Id);
                allTreeViewWrappers.Add(temp);
                temp.values = prop.Copy();
                slist.Add(temp);
                Id++;
            }while (prop.NextVisible(false));
        }
Beispiel #2
0
        public bool SetData(Transform root, Transform root_prefab, System.Action <IEnumerable <ViewElementPropertyOverrideData> > OnImport, ViewSystemNode node)
        {
            this.root        = root;
            this.root_prefab = root_prefab;
            this.node        = node;
            this.OnImport    = OnImport;
            titleContent     = new GUIContent("ViewElement Overrides Importer");

            propertyModification = PrefabUtility.GetPropertyModifications(root.gameObject)
                                   .ToArray();

            var group = propertyModification.GroupBy(x => x.target);

            var groupedByTarget = group.Where(m => m.Key != null).ToDictionary(o => o.Key, o => o.ToList());

            foreach (var target in groupedByTarget.Keys)
            {
                var groupedByProperty = groupedByTarget[target].GroupBy(x => x.propertyPath.Split('.')[0]).ToDictionary(o => o.Key, o => o.ToList());
                foreach (var property in groupedByProperty.Keys)
                {
                    // This find the orignal SerializedObject
                    var so = new SerializedObject(target);
                    // This find the orignal SerializedProperty
                    var sp = so.FindProperty(property);
                    if (VS_EditorUtility.IsPropertyNeedIgnore(sp))
                    {
                        continue;
                    }
                    var temp = new OverridesPropertiesCheckerData();
                    temp.serializedPropertyType          = sp.propertyType;
                    temp.overrideData.targetPropertyName = property;
                    //temp.overrideData.targetPropertyType = sp.propertyType.ToString();
                    //temp.overrideData.targetPropertyPath = VS_EditorUtility.ParseUnityEngineProperty(property);

                    Transform t;
                    if (sp.serializedObject.targetObject as Component == null)
                    {
                        t = ((GameObject)sp.serializedObject.targetObject).transform;
                    }
                    else
                    {
                        t = ((Component)sp.serializedObject.targetObject).transform;
                    }

                    var path     = AnimationUtility.CalculateTransformPath(t, root);
                    var selfName = root_prefab.name.Length + 1;
                    if (path.Length > selfName - 1)
                    {
                        path = path.Substring(selfName, path.Length - selfName);
                    }
                    else if (path.Length == selfName - 1)
                    {
                        path = "";
                    }
                    temp.overrideData.targetTransformPath = path;
                    temp.overrideData.targetComponentType = target.GetType().ToString();
                    temp.displayName = $"{sp.displayName}  ({property})";

                    //Find the prefab instance SerializedObject

                    var overrideGameObject = root.Find(path);
                    if (overrideGameObject == null)
                    {
                        ViewSystemLog.LogError("Target GameObject is not found, this feature only works on a root prefab instance, make sure which is not a child of other prefab instance.");
                        return(false);
                    }

                    UnityEngine.Object obj;
                    if (target is GameObject)
                    {
                        obj = overrideGameObject.gameObject;
                    }
                    else
                    {
                        obj = overrideGameObject.GetComponent(target.GetType());
                    }
                    var so_instance = new SerializedObject(obj);
                    //Find the prefab instance SerializedProperty
                    var sp_instance = so_instance.FindProperty(property);

                    // Add PropertyOverride to OverridesPropertiesCheckerData
                    PropertyOverride overProperty = new PropertyOverride();
                    overProperty.SetValue(sp_instance);
                    temp.overrideData.Value = overProperty;

                    // Add OverridesPropertiesCheckerData to list wait for user check
                    overridesPropertiesCheckerDatas.Add(temp);
                }
            }
            maxSize = new Vector2(800, 800);
            return(true);
        }