コード例 #1
0
        private void onDrawInspectorPanel()
        {
            if (selectedNode == null)
            {
                return;
            }
            if (selectedNode.taskType == TaskType.ACTION)
            {
                ActionTreeTask actionTask = selectedNode as ActionTreeTask;
                if (actionTask != null && selectedSerializedAction == null)
                {
                    //create serialized object for editor modification
                    selectedSerializedAction = new SerializedObject(selectedNode);
                    selectedSerializedAction.Update();
                }

                selectedSerializedAction.Update();
                ActionTreeTask task = selectedNode as ActionTreeTask;
                currentProperties = task.getAllProperties(selectedSerializedAction);
                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField(task.taskTypeName);
                EditorGUILayout.Space(10);
                foreach (SerializedProperty p in currentProperties)
                {
                    EditorGUILayout.PropertyField(p);
                }
                EditorGUILayout.EndVertical();

                selectedSerializedAction.ApplyModifiedProperties();
            }
            else
            {
                GUILayout.Label("Selected node isn't an action node");
            }
        }
コード例 #2
0
        private void getAllTasks()
        {
            behaviourTasks = Base.CommonCode.Common.FindAssetsByType <BehaviourTreeTask>();
            List <CompositeTreeTask> allData_Composites = Base.CommonCode.Common.FindAssetsByType <CompositeTreeTask>();
            List <DecoratorTreeTask> allData_Decorators = Base.CommonCode.Common.FindAssetsByType <DecoratorTreeTask>();

            behaviourTasks_Composite.Clear();
            behaviourTasks_Decorators.Clear();
            behaviourTasks_Actions.Clear();
            foreach (CompositeTreeTask t in allData_Composites)
            {
                if (t.useAsTaskSourceEditor)
                {
                    behaviourTasks_Composite.Add(t);
                }
            }
            foreach (DecoratorTreeTask t in allData_Decorators)
            {
                if (t.useAsTaskSourceEditor)
                {
                    behaviourTasks_Decorators.Add(t);
                }
            }
            foreach (BehaviourTreeTask t in behaviourTasks)
            {
                ActionTreeTask current = t as ActionTreeTask;
                if (current != null && current.useAsTaskSourceEditor)
                {
                    behaviourTasks_Actions.Add(current);
                }
            }
        }
コード例 #3
0
        ///////////////////////////////////////////////////////
        #endregion

        private void processEvents()
        {
            Event currentEvent = Event.current;

            if (currentEvent.type == EventType.MouseDown && currentNode == null)
            {
                //Debug.Log("mouse pos scaled:  " + mousePosition + " mouse position normal: " + currentEvent.mousePosition+" scaling: "+scaling);
                currentNode = getNodeAt(currentEvent.mousePosition - new Vector2(leftPanelSize.x, topPanelHeight));
                if (currentNode != null)
                {
                    localOffsetForDrag     = currentEvent.mousePosition;
                    Selection.activeObject = currentNode;

                    //set as selectd node
                    selectedNode = currentNode;
                    ActionTreeTask actionTask = selectedNode as ActionTreeTask;
                    if (actionTask != null)
                    {
                        //create serialized object for editor modification
                        selectedSerializedAction = new SerializedObject(selectedNode);
                        selectedSerializedAction.Update();
                    }

                    GUI.changed = true;
                }
                else
                {
                    if (currentEvent.mousePosition.x > leftPanelSize.x && currentEvent.mousePosition.x < this.position.width - GUI.skin.verticalScrollbar.fixedWidth * 2.5f &&
                        currentEvent.mousePosition.y < this.position.height - 20.0f)
                    {
                        draggingCanvas         = true;
                        draggingOffset         = currentEvent.mousePosition + scrollPosition;
                        Selection.activeObject = selectedBehaviour;
                    }
                }
            }
            else if (currentEvent.type == EventType.MouseDrag && currentNode != null)
            {
                Undo.RecordObject(selectedBehaviour, "Drag panel");
                Rect    oldRect = currentNode.NodeRect;
                Vector2 offset  = (currentEvent.mousePosition - localOffsetForDrag) / scaling;
                localOffsetForDrag   = currentEvent.mousePosition;
                oldRect.position    += offset;
                oldRect.position     = new Vector2(Mathf.Clamp(oldRect.position.x, 0, 10000), Mathf.Clamp(oldRect.position.y, 0, 10000));
                currentNode.NodeRect = oldRect;
                GUI.changed          = true;
            }
            else if (currentEvent.type == EventType.MouseDrag && draggingCanvas)
            {
                Undo.RecordObject(selectedBehaviour, "Drag view");
                scrollPosition = draggingOffset - currentEvent.mousePosition;
                GUI.changed    = true;
            }
            else if (currentEvent.type == EventType.MouseUp && currentNode != null)
            {
                currentNode = null;
            }
            else if (currentEvent.type == EventType.MouseUp && draggingCanvas)
            {
                draggingCanvas = false;
            }
        }