Exemplo n.º 1
0
 public OverridesPropertiesCheckerData()
 {
     overrideData = new ViewElementPropertyOverrideData();
 }
        private void CacheComponent()
        {
            if (m_ComponentTreeViewState == null)
            {
                m_ComponentTreeViewState = new TreeViewState();
            }

            componentTreeView = new ComponentTreeView(
                currentSelectGameObject,
                viewPageItem.viewElement,
                m_ComponentTreeViewState,
                currentSelectGameObject == target,
                (sp, path) =>
            {
                return(viewPageItem.overrideDatas.Where(
                           m =>
                           m.targetPropertyName == sp.name &&
                           m.targetTransformPath == path &&
                           m.targetComponentType == sp.serializedObject.targetObject.GetType().ToString()
                           ).Count() > 0);
            },
                () =>
            {
            });

            componentTreeView.OnItemClick += (sp) =>
            {
                Component c;
                try
                {
                    c = (Component)sp.serializedObject.targetObject;
                }
                catch
                {
                    c = ((GameObject)sp.serializedObject.targetObject).transform;
                }

                if (sp.propertyType == SerializedPropertyType.Generic)
                {
                    System.Type parentType = sp.serializedObject.targetObject.GetType();

                    System.Reflection.FieldInfo fi = parentType.GetField(sp.propertyPath);

                    System.Type propertyType = null;
                    if (fi != null)
                    {
                        propertyType = fi.FieldType;
                    }

                    string propertyName = sp.propertyPath;

                    if (parentType.ToString().Contains("UnityEngine."))
                    {
                        if (propertyName == "m_Navigation")
                        {
                            var content = new GUIContent("UnityEngine.UI.Navigation is not supported with ViewSystem OverrideSystem");
#if UNITY_2019_1_OR_NEWER
                            editor.ShowNotification(content, toastMessageFadeOutTimt);
#else
                            editor.ShowNotification(content);
#endif
                            return;
                        }
                        propertyName = ViewSystemUtilitys.ParseUnityEngineProperty(sp.propertyPath);
                    }

                    System.Reflection.PropertyInfo pi = parentType.GetProperty(propertyName);
                    if (pi != null && fi == null)
                    {
                        // ViewSystemLog.LogError("property not found");
                        // editor.ShowNotification(new GUIContent("property not found"), toastMessageFadeOutTimt);
                        // return;
                        propertyType = pi.PropertyType;
                    }

                    if (!propertyType.IsSubclassOf(typeof(UnityEngine.Events.UnityEvent)) &&
                        !propertyType.IsAssignableFrom(typeof(UnityEngine.Events.UnityEvent)))
                    {
                        var content = new GUIContent("Currently only support UnityEvent without parameters");
                        ViewSystemLog.LogError(content.text);
#if UNITY_2019_1_OR_NEWER
                        editor.ShowNotification(content, toastMessageFadeOutTimt);
#else
                        editor.ShowNotification(content);
#endif
                        return;
                    }

                    var eventData = new ViewElementEventData();
                    eventData.targetTransformPath = AnimationUtility.CalculateTransformPath(c.transform, target.transform);
                    eventData.targetPropertyName  = sp.name;
                    eventData.targetComponentType = sp.serializedObject.targetObject.GetType().ToString();
                    //eventData.targetPropertyType = sp.propertyType.ToString();
                    //eventData.targetPropertyPath = propertyName;

                    if (viewPageItem.eventDatas == null)
                    {
                        viewPageItem.eventDatas = new List <ViewElementEventData>();
                    }

                    var current = viewPageItem.eventDatas
                                  .Where(x =>
                                         x.targetTransformPath == eventData.targetTransformPath &&
                                         x.targetComponentType == eventData.targetComponentType &&
                                         x.targetPropertyName == eventData.targetPropertyName
                                         );

                    if (current.Count() > 0)
                    {
                        if (current.Where(m => string.IsNullOrEmpty(m.scriptName) && string.IsNullOrEmpty(m.methodName)).Count() > 0)
                        {
                            ViewSystemLog.LogError("You Have 1 event doesn't setup yet");
                            var errorContent = new GUIContent("You Have 1 event doesn't setup yet");
#if UNITY_2019_1_OR_NEWER
                            editor.ShowNotification(errorContent, toastMessageFadeOutTimt);
#else
                            editor.ShowNotification(errorContent);
#endif
                            return;
                        }
                    }

                    var error = new GUIContent("Event Add Success");
                    viewPageItem.eventDatas.Add(eventData);
#if UNITY_2019_1_OR_NEWER
                    editor.ShowNotification(error, toastMessageFadeOutTimt);
#else
                    editor.ShowNotification(error);
#endif
                }
                else
                {
                    var overrideData = new ViewElementPropertyOverrideData();
                    overrideData.targetTransformPath = AnimationUtility.CalculateTransformPath(c.transform, target.transform);
                    overrideData.targetPropertyName  = sp.name;
                    overrideData.targetComponentType = sp.serializedObject.targetObject.GetType().ToString();
                    //overrideData.targetPropertyType = sp.propertyType.ToString();
                    //overrideData.targetPropertyPath = VS_EditorUtility.ParseUnityEngineProperty(sp.propertyPath);
                    overrideData.Value.SetValue(sp);
                    if (viewPageItem.overrideDatas == null)
                    {
                        viewPageItem.overrideDatas = new List <ViewElementPropertyOverrideData>();
                    }

                    var current = viewPageItem.overrideDatas
                                  .SingleOrDefault(x =>
                                                   x.targetTransformPath == overrideData.targetTransformPath &&
                                                   x.targetComponentType == overrideData.targetComponentType &&
                                                   x.targetPropertyName == overrideData.targetPropertyName
                                                   );

                    if (current != null)
                    {
                        current = overrideData;
#if UNITY_2019_1_OR_NEWER
                        editor.ShowNotification(new GUIContent("This property is already in override list."), toastMessageFadeOutTimt);
#else
                        editor.ShowNotification(new GUIContent("This property is already in override list."));
#endif
                    }
                    else
                    {
                        viewPageItem.overrideDatas.Add(overrideData);
#if UNITY_2019_1_OR_NEWER
                        editor.ShowNotification(new GUIContent("Property override add success"), toastMessageFadeOutTimt);
#else
                        editor.ShowNotification(new GUIContent("Property override add success"));
#endif
                    }
                }
            };
        }
Exemplo n.º 3
0
        void DrawValue(SerializedPropertyType type, ViewElementPropertyOverrideData overrideData)
        {
            if (type != SerializedPropertyType.Generic)
            {
                Color backgroundColor = GUI.backgroundColor;
                GUI.backgroundColor *= new Color(1f, 1f, 1f, 0.5f);
                switch (type)
                {
                case SerializedPropertyType.Vector2:
                    GUILayout.Box($"Vector2 {overrideData.Value.GetValue().ToString()}", Drawer.valueBoxStyle, GUILayout.Height(16), GUILayout.Width(vauleBoxWidth));
                    break;

                case SerializedPropertyType.Vector3:
                    GUILayout.Box($"Vector3 {overrideData.Value.GetValue().ToString()}", Drawer.valueBoxStyle, GUILayout.Height(16), GUILayout.Width(vauleBoxWidth));
                    break;

                case SerializedPropertyType.Float:
                    GUILayout.Box(overrideData.Value.GetValue().ToString(), Drawer.valueBoxStyle, GUILayout.Height(16), GUILayout.Width(vauleBoxWidth));
                    break;

                case SerializedPropertyType.Integer:
                    GUILayout.Box(overrideData.Value.GetValue().ToString(), Drawer.valueBoxStyle, GUILayout.Height(16), GUILayout.Width(vauleBoxWidth));
                    break;

                case SerializedPropertyType.String:
                    GUILayout.Box(new GUIContent("\"" + overrideData.Value.StringValue + "\"", overrideData.Value.StringValue), Drawer.valueBoxStyle, GUILayout.Height(16), GUILayout.Width(vauleBoxWidth));
                    break;

                case SerializedPropertyType.Boolean:
                    GUILayout.Box(overrideData.Value.GetValue().ToString(), Drawer.valueBoxStyle, GUILayout.Height(16), GUILayout.Width(vauleBoxWidth));
                    break;

                case SerializedPropertyType.Color:
                    using (var disable = new EditorGUI.DisabledGroupScope(true))
                    {
                        EditorGUILayout.ColorField((Color)overrideData.Value.GetValue(), GUILayout.Height(16), GUILayout.Width(vauleBoxWidth));
                    }
                    break;

                case SerializedPropertyType.LayerMask:
                    GUILayout.Box(overrideData.Value.GetValue().ToString(), Drawer.valueBoxStyle, GUILayout.Height(16), GUILayout.Width(vauleBoxWidth));
                    break;

                case SerializedPropertyType.ObjectReference:
                    if (overrideData.Value.ObjectReferenceValue == null)
                    {
                        GUILayout.Box("Null", Drawer.valueBoxStyle, GUILayout.Height(16), GUILayout.Width(vauleBoxWidth));
                    }
                    else
                    {
                        using (var disable = new EditorGUI.DisabledGroupScope(true))
                        {
                            EditorGUILayout.ObjectField(overrideData.Value.ObjectReferenceValue, overrideData.Value.ObjectReferenceValue.GetType(), false, GUILayout.Height(16), GUILayout.Width(vauleBoxWidth));
                        }
                    }

                    //GUILayout.Box(overrideData.Value.IntValue.ToString(), Drawer.valueBoxStyle, GUILayout.Height(16), GUILayout.Width(150));
                    break;

                default:
                    GUILayout.Box(new GUIContent(type.ToString(), type.ToString()), Drawer.valueBoxStyle, GUILayout.Height(16), GUILayout.Width(vauleBoxWidth));
                    break;
                }
                GUI.backgroundColor = backgroundColor;
            }
        }
 public ViewElementPropertyOverrideDataWrapper(ViewElementPropertyOverrideData viewElementPropertyOverrideData)
 {
     lineHeight = EditorGUIUtility.singleLineHeight * 2.5f;
     this.viewElementPropertyOverrideData = viewElementPropertyOverrideData;
 }