Beispiel #1
0
        private void CreateConnection()
        {
            //return if in out point are null
            if (selectedInPoint == null && selectedOutPoint == null)
            {
                return;
            }

            var connection = new Connection(selectedInPoint, selectedOutPoint, OnClickRemoveConnection);

            //remove old out connection(out connection has only one)
            if (selectedOutPoint.connectedConnection != null)
            {
                var oldConn = selectedOutPoint.connectedConnection;
                if (Connections.Contains(oldConn))
                {
                    Connections.Remove(oldConn);
                }
            }

            selectedOutPoint.SetConnection(connection);
            if (!Connections.Contains(connection))
            {
                Connections.Add(connection);
            }
        }
Beispiel #2
0
        private void InitEditor()
        {
            nodeActionList = CurrentStoryLine.OnLoadNodes();

            //editor background color
            backgroundColor = new Texture2D(1, 1, TextureFormat.RGBA32, false);
            backgroundColor.SetPixel(0, 0, new Color(0.2f, 0.2f, 0.2f));
            backgroundColor.Apply();

            //node radius
            var radius = 10;

            InPointStyle = new GUIStyle();
            InPointStyle.normal.background = AssetDatabase.LoadAssetAtPath("Assets/ImgSources/T_circle.png", typeof(Texture2D)) as Texture2D;
            InPointStyle.hover.background  = AssetDatabase.LoadAssetAtPath("Assets/ImgSources/T_circle_active.png", typeof(Texture2D)) as Texture2D;
            //InPointStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn left.png") as Texture2D;
            //InPointStyle.active.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn left on.png") as Texture2D;
            //InPointStyle.border = new RectOffset(4, 4, radius, radius);

            outPointStyle = new GUIStyle();
            outPointStyle.normal.background = AssetDatabase.LoadAssetAtPath("Assets/ImgSources/T_circle.png", typeof(Texture2D)) as Texture2D;
            outPointStyle.hover.background  = AssetDatabase.LoadAssetAtPath("Assets/ImgSources/T_circle_active.png", typeof(Texture2D)) as Texture2D;
            //OutPointStyle.normal.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn right.png") as Texture2D;
            //OutPointStyle.active.background = EditorGUIUtility.Load("builtin skins/darkskin/images/btn right on.png") as Texture2D;
            //OutPointStyle.border = new RectOffset(4, 4, radius, radius);

            //draw start node
            var starttex       = new Texture2D(12, 12);
            var fillColorArray = starttex.GetPixels();

            for (var i = 0; i < fillColorArray.Length; ++i)
            {
                fillColorArray[i] = new Color(0.2f, 0.8f, 0.2f, 0.7f);
            }
            starttex.SetPixels(fillColorArray);
            starttex.Apply();

            var startNodeStyle = new GUIStyle();

            startNodeStyle.normal.background = starttex;

            var starttex2       = new Texture2D(12, 12);
            var fillColorArray2 = starttex2.GetPixels();

            for (var i = 0; i < fillColorArray2.Length; ++i)
            {
                fillColorArray2[i] = new Color(0.2f, 0.8f, 0.2f, 0.9f);
            }
            starttex2.SetPixels(fillColorArray2);
            starttex2.Apply();

            var startSelectedNodeStyle = new GUIStyle();

            startSelectedNodeStyle.normal.background = starttex2;

            var tex = new Texture2D(12, 12);

            fillColorArray = tex.GetPixels();
            for (var i = 0; i < fillColorArray.Length; ++i)
            {
                fillColorArray[i] = new Color(0.4f, 0.4f, 0.4f, 0.7f);
            }
            tex.SetPixels(fillColorArray);
            tex.Apply();

            NodeStyle = new GUIStyle();
            NodeStyle.normal.background = tex;
            NodeStyle.normal.textColor  = Color.gray;
            NodeStyle.border            = new RectOffset(radius, radius, radius, radius);

            var tex2 = new Texture2D(12, 12);

            fillColorArray2 = tex2.GetPixels();
            for (var i = 0; i < fillColorArray2.Length; ++i)
            {
                fillColorArray2[i] = new Color(0.4f, 0.4f, 0.4f, 0.9f);
            }
            tex2.SetPixels(fillColorArray2);
            tex2.Apply();

            SelectedNodeStyle = new GUIStyle();
            SelectedNodeStyle.normal.background = tex2;
            SelectedNodeStyle.normal.textColor  = Color.yellow;
            SelectedNodeStyle.border            = new RectOffset(radius, radius, radius, radius);

            //import existed node
            if (nodeActionList.Count > 0)
            {
                foreach (var n in nodeActionList)
                {
                    float _width  = NodeWidth;
                    float _height = 0;
                    switch (n.ActionType)
                    {
                    case ActionTypes.StartPoint:
                        n.CanEdit = false;
                        break;

                    case ActionTypes.BrancheBox:
                        (n as BrancheBox).SetOutPointStyle(outPointStyle, onClickOutPoint);
                        break;
                    }

                    var rectSize = GetNodeRectSize(n.ActionType);
                    n.SetRectInfo(rectSize);

                    if (n.ActionType == ActionTypes.StartPoint)
                    {
                        n.SetNodeStyle(startNodeStyle, startSelectedNodeStyle, InPointStyle, outPointStyle, onClickInPoint, onClickOutPoint, OnClickCopyNode, OnClickRemoveNode);
                    }
                    else
                    {
                        n.SetNodeStyle(NodeStyle, SelectedNodeStyle, InPointStyle, outPointStyle, onClickInPoint, onClickOutPoint, OnClickCopyNode, OnClickRemoveNode);
                    }
                }

                //import connections
                Connections = CurrentStoryLine.OnLoadConnections();
                foreach (var c in Connections)
                {
                    c.OnClickRemoveConnection = OnClickRemoveConnection;

                    if (c.InPoint.targetItemId > -1)
                    {
                    }
                    else
                    {
                        c.InPoint = nodeActionList.Where(n => n.Id == c.InPoint.targetNodeId).FirstOrDefault().InPoint;
                    }

                    ConnectionPoint outPoint = new ConnectionPoint();
                    if (c.OutPoint.targetItemId > -1)
                    {
                        var node = nodeActionList.Where(n => n.Id == c.OutPoint.targetNodeId).FirstOrDefault();
                        if (node is BrancheBox)
                        {
                            outPoint = (node as BrancheBox).outPointList[c.OutPoint.targetItemId];
                        }
                    }
                    else
                    {
                        outPoint = nodeActionList.Where(n => n.Id == c.OutPoint.targetNodeId).FirstOrDefault().OutPoint;
                    }

                    //set out connection(each node only have one out connection)
                    outPoint.SetConnection(c);
                    c.OutPoint = outPoint;
                }
            }
            //or create new
            else
            {
                var y = position.height / 5;
                StartNode = new EditorStartPoint();
                //add start node to action nodes
                StartNode.Init(
                    new Vector2(20, y), new Vector2(NodeWidth / 2, 30),
                    startNodeStyle, startSelectedNodeStyle, null, outPointStyle, null, onClickOutPoint, null, null,
                    0, _canEdit: false);

                if (!nodeActionList.Contains(StartNode))
                {
                    nodeActionList.Insert(0, StartNode);
                }
            }
        }