예제 #1
0
        static bool ExpressionProperty(FieldInfo p_fieldInfo, Object p_object, GUIContent p_name, IReferencable p_reference)
        {
            ExpressionAttribute expressionAttribute = p_fieldInfo.GetAttribute <ExpressionAttribute>();

            if (expressionAttribute == null)
            {
                return(false);
            }

            FieldInfo expressionField    = p_object.GetType().GetField(expressionAttribute.expression);
            FieldInfo useExpressionField = p_object.GetType().GetField(expressionAttribute.useExpression);

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginHorizontal();

            if ((bool)useExpressionField.GetValue(p_object))
            {
                GUILayout.BeginHorizontal();
                GUI.color = DashEditorCore.EditorConfig.theme.ParameterColor;
                GUILayout.Label(p_name, GUILayout.Width(160));
                HandleReferencing(p_reference, expressionField, true);
                string expression = GUILayout.TextArea((string)expressionField.GetValue(p_object), GUILayout.ExpandWidth(true));
                GUI.color = Color.white;
                expressionField.SetValue(p_object, expression);
                GUILayout.EndHorizontal();
            }
            else
            {
                PropertyField(p_fieldInfo, p_object, p_reference, p_fieldInfo);
            }

            bool useExpression = (bool)useExpressionField.GetValue(p_object);

            GUI.color = useExpression ? DashEditorCore.EditorConfig.theme.ParameterColor : Color.gray;
            if (GUILayout.Button(IconManager.GetIcon("Settings_Icon"), GUIStyle.none, GUILayout.Height(16), GUILayout.MaxWidth(16)))
            {
                useExpressionField.SetValue(p_object, !useExpression);
            }
            GUI.color = Color.white;

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space(4);

            if (EditorGUI.EndChangeCheck())
            {
                return(true);
            }

            return(false);
        }
예제 #2
0
        static bool PopupProperty(FieldInfo p_fieldInfo, Object p_object, GUIContent p_name)
        {
            if (!IsPopupProperty(p_fieldInfo))
            {
                return(false);
            }

            ClassPopupAttribute popupAttribute = p_fieldInfo.GetCustomAttribute <ClassPopupAttribute>();

            // We are caching assembly domain lookups as it is heavy operation
            // TODO need to enable option to recache later since users can implement new types
            if (!cachedTypes.ContainsKey(popupAttribute.ClassType))
            {
                cachedTypes[popupAttribute.ClassType] = ReflectionUtils.GetAllTypes(popupAttribute.ClassType);
            }

            List <string> options = cachedTypes[popupAttribute.ClassType].Select(c => c.ToString()).ToList();

            options.Insert(0, "NONE");
            object value = p_fieldInfo.GetValue(p_object);
            int    index = value == null ? 0 : options.IndexOf(value.ToString());

            EditorGUILayout.BeginHorizontal();

            EditorGUI.BeginChangeCheck();
            int newIndex = EditorGUILayout.Popup(p_name, index, options.ToArray());

            if (index != 0)
            {
                if (GUILayout.Button(IconManager.GetIcon("Script_Icon"), GUIStyle.none, GUILayout.MaxWidth(20), GUILayout.MaxHeight(20)))
                {
                    AssetDatabase.OpenAsset(EditorUtils.GetScriptFromType(cachedTypes[popupAttribute.ClassType][index - 1]), 1);
                }
            }
            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                if (newIndex != index)
                {
                    p_fieldInfo.SetValue(p_object,
                                         newIndex == 0 ? null : Activator.CreateInstance(cachedTypes[popupAttribute.ClassType][newIndex - 1]));
                }

                return(true);
            }

            return(false);
        }
예제 #3
0
        public virtual void DrawGUI(Rect p_rect)
        {
            GUISkin skin = DashEditorCore.Skin;
            rect = new Rect(rect.x, rect.y, Size.x, Size.y);

            Rect offsetRect = new Rect(rect.x + Graph.viewOffset.x, rect.y + Graph.viewOffset.y, Size.x, Size.y);
            
            if (!p_rect.Contains(new Vector2(offsetRect.x, offsetRect.y)) &&
                !p_rect.Contains(new Vector2(offsetRect.x + offsetRect.width, offsetRect.y)) &&
                !p_rect.Contains(new Vector2(offsetRect.x, offsetRect.y + offsetRect.height)) &&
                !p_rect.Contains(new Vector2(offsetRect.x + offsetRect.width, offsetRect.y + offsetRect.height)))
                return;

            if (BaseGUIEnabled)
            {
                GUI.color = DashEditorCore.EditorConfig.theme.GetNodeBackgroundColorByCategory(Category);

                if (!IsSynchronous() && DashEditorCore.DetailsVisible && DashEditorCore.EditorConfig.showNodeAsynchronity)
                {
                    GUI.DrawTexture(
                        new Rect(offsetRect.x + offsetRect.width - 24, offsetRect.y - 20, 20, 20),
                        IconManager.GetIcon("time_icon"));
                }

                GUI.Box(offsetRect, "", skin.GetStyle(BackgroundSkinId));

                DrawTitle(offsetRect);
            }

            if (DashEditorCore.DetailsVisible)
            {
                DrawCustomGUI(offsetRect);
                
                DrawId(offsetRect);
            }

            DrawOutline(offsetRect);

            DrawConnectors(p_rect);
        }
예제 #4
0
 private void OnEnable()
 {
     if (EventNodeIcon == null)
     {
         EventNodeIcon = IconManager.GetIcon("event_icon");
     }
     if (AnimationNodeIcon == null)
     {
         AnimationNodeIcon = IconManager.GetIcon("animation_icon");
     }
     if (ModifierNodeIcon == null)
     {
         ModifierNodeIcon = IconManager.GetIcon("retargeting_icon");
     }
     if (CreationNodeIcon == null)
     {
         CreationNodeIcon = IconManager.GetIcon("spawn_icon");
     }
     if (LogicNodeIcon == null)
     {
         LogicNodeIcon = IconManager.GetIcon("settings_icon");
     }
 }
예제 #5
0
 protected override void DrawCustomGUI(Rect p_rect)
 {
     GUI.DrawTexture(new Rect(p_rect.x + p_rect.width / 2 - 24, p_rect.y + 28, 48, 48),
                     IconManager.GetIcon("rollin_icon"));
 }
예제 #6
0
        static bool ParameterProperty(FieldInfo p_fieldInfo, Object p_object, GUIContent p_name, IReferencable p_reference)
        {
            if (!IsParameterProperty(p_fieldInfo))
            {
                return(false);
            }

            Parameter param = (Parameter)p_fieldInfo.GetValue(p_object);

            if (param == null)
            {
                RecreateParameter(p_fieldInfo, p_object);
                return(true);
            }

            // Can happen due to serialization/migration error
            if (param != null)
            {
                EditorGUI.BeginChangeCheck();

                EditorGUILayout.BeginHorizontal();

                if (param.isExpression)
                {
                    GUILayout.BeginHorizontal();
                    GUI.color = DashEditorCore.EditorConfig.theme.ParameterColor;
                    GUILayout.Label(p_name, GUILayout.Width(160));
                    HandleReferencing(p_reference, p_fieldInfo, false, param);
                    param.expression = GUILayout.TextArea(param.expression, GUILayout.ExpandWidth(true));
                    GUI.color        = Color.white;
                    GUILayout.EndHorizontal();
                }
                else
                {
                    ButtonAttribute button = p_fieldInfo.GetAttribute <ButtonAttribute>();
                    if (button != null)
                    {
                        GUILayout.Label(p_name, GUILayout.Width(160));
                        if (param.IsDefault())
                        {
                            GUI.color = Color.yellow;
                            if (GUILayout.Button(button.NullLabel))
                            {
                                MethodInfo method = p_object.GetType().GetMethod(button.MethodName, BindingFlags.Instance | BindingFlags.NonPublic);
                                param.GetValueFieldInfo().SetValue(param, method.Invoke(p_object, null));
                            }
                            GUI.color = Color.white;
                        }
                        else
                        {
                            if (GUILayout.Button(button.NonNullLabel))
                            {
                                MethodInfo method = p_object.GetType().GetMethod(button.MethodName, BindingFlags.Instance | BindingFlags.NonPublic);
                                param.GetValueFieldInfo().SetValue(param, method.Invoke(p_object, null));
                            }
                        }
                    }
                    else
                    {
                        PropertyField(param.GetValueFieldInfo(), param, p_reference, p_fieldInfo);
                    }
                }


                GUI.color = param.isExpression ? DashEditorCore.EditorConfig.theme.ParameterColor : Color.gray;
                if (GUILayout.Button(IconManager.GetIcon("Settings_Icon"), GUIStyle.none, GUILayout.Height(16), GUILayout.MaxWidth(16)))
                {
                    param.isExpression = !param.isExpression;
                }
                //param.isExpression = GUILayout.Toggle(param.isExpression, "", GUILayout.MaxWidth(14));
                GUI.color = Color.white;

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space(4);

                if (EditorGUI.EndChangeCheck())
                {
                    return(true);
                }
            }
            else
            {
                GUI.color = Color.red;
                GUILayout.Label("Serialization error on " + p_fieldInfo.Name + "\nYou can use SerializationInvalidation in menu to try fix this.");
                EditorGUILayout.Space(2);
                GUI.color = Color.white;
            }

            return(false);
        }
예제 #7
0
        public void DrawGUI()
        {
            Rect offsetRect = new Rect(rect.x + Graph.viewOffset.x, rect.y + Graph.viewOffset.y, rect.width, rect.height);

            GUI.color = color;

            GUI.Box(offsetRect, "", DashEditorCore.Skin.GetStyle("GraphBox"));

            Rect titleRect = new Rect(offsetRect.x + 12, offsetRect.y, offsetRect.width, 40);

            if (Event.current.type == EventType.MouseDown && titleRect.Contains(Event.current.mousePosition))
            {
                if (EditorApplication.timeSinceStartup - _lastClickTime < 0.3)
                {
                    DashEditorCore.editingBoxComment = this;
                }
                _lastClickTime = EditorApplication.timeSinceStartup;
            }

            GUI.DrawTexture(new Rect(offsetRect.x + offsetRect.width - 32, offsetRect.y + offsetRect.height - 32, 32, 32), IconManager.GetIcon("Resize_Icon"));
            GUI.color = Color.white;
            GUIStyle style = new GUIStyle();

            style.fontStyle        = FontStyle.Bold;
            style.fontSize         = 24;
            style.normal.textColor = Color.white;
            style.alignment        = TextAnchor.LowerLeft;
            if (DashEditorCore.editingBoxComment == this)
            {
                EditorGUI.BeginChangeCheck();
                comment = GUI.TextField(titleRect, comment, style);
                if (EditorGUI.EndChangeCheck())
                {
                    DashEditorCore.SetDirty();
                }
            }
            else
            {
                GUI.Label(titleRect, comment, style);
            }
        }
예제 #8
0
        void DrawOutline(Rect p_rect)
        {
            if (SelectionManager.IsSelected(Graph.Nodes.IndexOf(this)))
            {
                GUI.color = Color.green;
                GUI.Box(new Rect(p_rect.x - 2, p_rect.y - 2, p_rect.width + 4, p_rect.height + 4),
                    "",  DashEditorCore.Skin.GetStyle("NodeSelected"));
            }
                
            if (IsExecuting || executeTime > 0)
            {
                if (!IsExecuting)
                {
                    executeTime -= .2f;
                }
                GUI.color = Color.cyan;
                GUI.Box(new Rect(p_rect.x - 2, p_rect.y - 2, p_rect.width + 4, p_rect.height + 4),
                    "",  DashEditorCore.Skin.GetStyle("NodeSelected"));
            }
            
            if (SelectionManager.IsSelecting(Graph.Nodes.IndexOf(this)))
            {
                GUI.color = Color.yellow;
                GUI.Box(new Rect(p_rect.x - 2, p_rect.y - 2, p_rect.width + 4, p_rect.height + 4),
                    "",  DashEditorCore.Skin.GetStyle("NodeSelected"));
            }
                
            if (hasErrorsInExecution)
            {
                GUI.color = Color.red;
                GUI.Box(new Rect(p_rect.x - 2, p_rect.y - 2, p_rect.width + 4, p_rect.height + 4),
                    "",  DashEditorCore.Skin.GetStyle("NodeSelected"));
                GUI.DrawTexture(new Rect(p_rect.x + 2, p_rect.y - 22, 16, 16),
                    IconManager.GetIcon("error_icon"));
            }

            int labelOffset = 0;
            if (this is InputNode)
            {
                InputNode node = this as InputNode;
                if (DashEditorCore.EditorConfig.editingController != null &&
                    DashEditorCore.EditorConfig.editingController.autoStart &&
                    DashEditorCore.EditorConfig.editingController.autoStartInput == node.Model.inputName) 
                {
                    GUI.color = Color.white;
                    GUIStyle style = new GUIStyle();
                    style.normal.textColor = Color.green;
                    style.fontStyle = FontStyle.Bold;
                    style.fontSize = 20;
                    style.alignment = TextAnchor.UpperCenter;
                    GUI.Label(new Rect(p_rect.x, p_rect.y + rect.height, rect.width, 20), "[START]", style);
                    labelOffset++;
                }
            }
            
            if (this is InputNode)
            {
                InputNode node = this as InputNode;
                if (DashEditorCore.EditorConfig.editingController != null &&
                    DashEditorCore.EditorConfig.editingController.autoOnEnable &&
                    DashEditorCore.EditorConfig.editingController.autoOnEnableInput == node.Model.inputName) 
                {
                    GUI.color = Color.white;
                    GUIStyle style = new GUIStyle();
                    style.normal.textColor = Color.green;
                    style.fontStyle = FontStyle.Bold;
                    style.fontSize = 20;
                    style.alignment = TextAnchor.UpperCenter;
                    GUI.Label(new Rect(p_rect.x, p_rect.y + rect.height + labelOffset * 25, rect.width, 20), "[ONENABLE]", style);
                    labelOffset++;
                }
            }

            if (Graph.previewNode == this)
            {
                GUI.color = Color.white;
                GUIStyle style = new GUIStyle();
                style.normal.textColor = Color.magenta;
                style.fontStyle = FontStyle.Bold;
                style.fontSize = 20;
                style.alignment = TextAnchor.UpperCenter;
                GUI.Label(new Rect(p_rect.x, p_rect.y + rect.height + labelOffset * 25, rect.width, 20), "[PREVIEW]", style);
            }

            GUI.color = Color.white;
        }
예제 #9
0
        public override void DrawInspectorControls(Rect p_rect)
        {
            if (!(this is IAnimationNodeBindable) || !DashEditorCore.EditorConfig.enableAnimateNodeInterface)
            {
                return;
            }

            Transform target = ResolveEditorTarget();

            if (target == null)
            {
                return;
            }

            GUIStyle style = new GUIStyle();

            GUI.backgroundColor     = new Color(0, 0, 0, 0.5f);
            style.normal.background = Texture2D.whiteTexture;
            GUI.Box(new Rect(p_rect.x, p_rect.y + p_rect.height + 4, 390, 38), "", style);
            GUI.backgroundColor = Color.white;

            GUILayout.BeginArea(new Rect(p_rect.x + 20, p_rect.y + p_rect.height + 8, p_rect.width - 20, 30));
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            style           = new GUIStyle(GUI.skin.button);
            style.fontStyle = FontStyle.Bold;

            GUI.enabled = ((IAnimationNodeBindable)this).IsFromEnabled();
            if (_bindFrom)
            {
                GUI.backgroundColor = new Color(1, 0, 0);
                if (GUILayout.Button("UNBIND FROM", style, GUILayout.Width(110), GUILayout.ExpandHeight(true)))
                {
                    _bindFrom = false;
                }
                GUI.backgroundColor = Color.white;
            }
            else
            {
                if (GUILayout.Button("BIND FROM", style, GUILayout.Width(110), GUILayout.ExpandHeight(true)))
                {
                    ((IAnimationNodeBindable)this).SetTargetFrom(target);
                    _bindTo   = false;
                    _bindFrom = true;
                }
            }

            GUILayout.FlexibleSpace();

            GUI.enabled = ((IAnimationNodeBindable)this).IsToEnabled();
            if (_bindTo)
            {
                GUI.backgroundColor = new Color(1, 0, 0);
                if (GUILayout.Button("UNBIND TO", style, GUILayout.Width(110), GUILayout.ExpandHeight(true)))
                {
                    _bindTo = false;
                }
                GUI.backgroundColor = Color.white;
            }
            else
            {
                if (GUILayout.Button("BIND TO", style, GUILayout.Width(110), GUILayout.ExpandHeight(true)))
                {
                    ((IAnimationNodeBindable)this).SetTargetTo(target);
                    _bindFrom = false;
                    _bindTo   = true;
                }
            }

            GUILayout.FlexibleSpace();

            GUI.backgroundColor    = new Color(1, .75f, .5f);
            style.fontSize         = 16;
            style.normal.textColor = GUI.backgroundColor;

            if (GUILayout.Button("PREVIEW", style, GUILayout.Width(100), GUILayout.ExpandHeight(true)))
            {
                TransformStorageData data = new TransformStorageData(target, TransformStorageOption.POSITION);
                AnimateOnTarget(target, NodeFlowDataFactory.Create())?.OnComplete(() =>
                {
                    DashTweenCore.Uninitialize();
                    data.Restore(target);
                }).Start();
            }

            GUI.backgroundColor = Color.white;
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            GUI.enabled = true;

            GUI.color = Color.yellow;
            GUI.DrawTexture(new Rect(p_rect.x + 8, p_rect.y + p_rect.height + 16, 16, 16),
                            IconManager.GetIcon("experimental_icon"));
            GUI.color = Color.white;

            if (_bindFrom)
            {
                ((IAnimationNodeBindable)this).GetTargetFrom(target);
            }
            else if (_bindTo)
            {
                ((IAnimationNodeBindable)this).GetTargetTo(target);
            }
        }