Example #1
0
        public void UpdateSize(int depth)
        {
            for (int i = 0; i < values.Length; i++)
            {
                values[i]?.UpdateSize(0);
            }

            for (int i = 1; i < codeConnections.Length; i++)
            {
                codeConnections[i]?.UpdateSize(depth + 1);
            }

            Width = 180;
            ICompilerValue value = values[0];

            if (value == null)
            {
                Width += CodeUtil.SubWidth;
            }
            else
            {
                Width += value.Width;
            }

            block.sizeDelta = new Vector2(Mathf.Ceil(Width), 76);

            //blockImage.color = CodeUtil.ChangeFunctionColor(Colors.GeneralColor, depth);
        }
Example #2
0
        string SaveValue(ICompilerValue value)
        {
            if (value == null)
            {
                return(Saving.CodeValueBegin.ToString() + Saving.CodeValueEnd.ToString());
            }

            var str = Saving.CodeValueBegin.ToString();

            str += value.Save();
            foreach (var v in value.Values)
            {
                str += SaveValue(v);
            }
            str += Saving.CodeValueEnd.ToString();
            return(str);
        }
Example #3
0
        void RecursiveValueConnect(ICompilerValue value, bool connectInitial)
        {
            if (connectInitial)
            {
                value.Offset.Connect();
            }
            else
            {
                value.Transform.SetAsLastSibling();
            }

            foreach (var v in value.Values)
            {
                if (v != null)
                {
                    RecursiveValueConnect(v, true);
                }
            }
        }
Example #4
0
        public void UpdateSize(int depth)
        {
            Width = 229 - CodeUtil.SubWidth;
            ICompilerValue value = values[0];

            if (value != null)
            {
                value.UpdateSize(0);
                Width += value.Width;
            }
            else
            {
                Width += CodeUtil.SubWidth;
            }


            Height = 200;
            ICompilerCode connection = codeConnections[1];

            while (connection != null)
            {
                connection.UpdateSize(depth + 1);
                Height    += connection.Height;
                connection = connection.CodeConnections[0];
            }

            scope.sizeDelta = new Vector2(40, Height - 120);
            endConnection.anchoredPosition = new Vector2(0, -Height);


            block.sizeDelta = new Vector2(Mathf.Ceil(Width), 76);


            var c = CodeUtil.ChangeFunctionColor(Colors.ConditionalColor, depth);

            foreach (var i in blockImages)
            {
                i.color = c;
            }
        }
Example #5
0
        public void UpdateSize(int depth)
        {
            /*for (int i = 0; i < values.Length; i++)
             * {
             *  values[i]?.UpdateSize();
             * }
             *
             * for (int i = 1; i < codeConnections.Length; i++)
             * {
             *  codeConnections[i]?.UpdateSize();
             * }*/

            for (int i = 0; i < codeConnections.Length; i++)
            {
                codeTest2[i] = codeConnections[i]?.Transform;
            }

            Width = 260 - CodeUtil.SubWidth;
            ICompilerValue value = values[0];

            if (value != null)
            {
                value.UpdateSize(0);
                Width += value.Width;
                //value = value.Values?.Length > 0 ? value.Values?[0] : null;
            }
            else
            {
                Width += CodeUtil.SubWidth;
            }

            if (depth >= 0)
            {
                var c1 = 0f;
                var c2 = 0f;

                Height = 360;
                ICompilerCode connection = codeConnections[1];
                while (connection != null)
                {
                    connection.UpdateSize(depth + 1);
                    Height    += connection.Height;
                    c1        += connection.Height;
                    connection = connection.CodeConnections[0];
                }

                connection = codeConnections[2];
                while (connection != null)
                {
                    connection.UpdateSize(depth + 1);
                    Height    += connection.Height;
                    c2        += connection.Height;
                    connection = connection.CodeConnections[0];
                }

                scope1.sizeDelta         = new Vector2(40, codeConnections[1] != null ? c1 + 80 : 80);
                scope2.anchoredPosition  = new Vector2(0, codeConnections[1] != null ? -c1 - 240 : -240);
                scope2.sizeDelta         = new Vector2(40, codeConnections[2] != null ? c2 + 40 : 40);
                nextCon.anchoredPosition = new Vector2(0, -Height);
            }

            block.sizeDelta = new Vector2(Mathf.Ceil(Width), 76);

            var c = CodeUtil.ChangeControlColor(Colors.ControlColor, depth);

            foreach (var i in blockImages)
            {
                i.color = c;
            }
        }
Example #6
0
        void MoveCode(Transform hit, bool left = true)
        {
            var canDropCode = previousConnection == null ||
                              (left ? ((byte)Settings.CodeDropType & 0b01) == 1 : ((byte)Settings.CodeDropType & 0b10) == 1);

            if (CanDelete())
            {
                switch (clonedObjectType)
                {
                case CodeType.Event:
                    CodeDelete(currentClonedObject.GetComponent <ICompilerEvent>());
                    Destroy(currentClonedObject.gameObject);
                    break;

                case CodeType.Function:
                    CodeDelete(currentClonedObject.GetComponent <ICompilerCode>());
                    break;

                case CodeType.Value:
                    ValueDelete(currentClonedObject.GetComponent <ICompilerValues>());
                    break;
                }

                currentClonedObject = null;

                //clickAudioSource.Play();
            }
            else
            {
                switch (clonedObjectType)
                {
                case CodeType.Event:
                    var curEvent = currentClonedObject.GetComponent <ICompilerEvent>();
                    if (hit && !hit.IsChildOf(otherCodeTransform))
                    {
                        var oldEvent = hit.GetComponentInParent <ICompilerEvent>();

                        ICompilerEvent nextCon = oldEvent.NextConnection;
                        oldEvent.NextConnection = curEvent;
                        curEvent.NextConnection = nextCon;

                        curEvent.Offset.Connection = oldEvent.NextConnectionObject;
                        if (curEvent.NextConnection != null)
                        {
                            nextCon.Offset.Connection = curEvent.NextConnectionObject;
                        }

                        currentClonedObject.SetParent(currentScriptObject, false);
                        currentClonedObject = null;
                        ReconnectAll();
                    }
                    else
                    {
                        if (!canDropCode)
                        {
                            var            prevConEvent = (ICompilerEvent)previousConnection;
                            ICompilerEvent nextCon      = prevConEvent.NextConnection;
                            prevConEvent.NextConnection = curEvent;
                            curEvent.NextConnection     = nextCon;

                            curEvent.Offset.Connection = prevConEvent.NextConnectionObject;
                            if (curEvent.NextConnection != null)
                            {
                                nextCon.Offset.Connection = curEvent.NextConnectionObject;
                            }

                            currentClonedObject.SetParent(currentScriptObject, false);
                            currentClonedObject = null;
                            ReconnectAll();
                        }
                        else
                        {
                            currentClonedObject.SetParent(otherCodeTransform);
                            currentClonedObject = null;
                            ReconnectOtherCode();
                        }
                    }

                    break;



                case CodeType.Function:
                    var func = currentClonedObject.GetComponent <ICompilerCode>();

                    var lastCodeInMove = func;
                    var lastFunc       = func.CodeConnections[0];

                    while (lastFunc != null)
                    {
                        lastCodeInMove = lastFunc;
                        lastFunc       = lastFunc.CodeConnections[0];
                    }

                    if (hit)
                    {
                        var connection = hit.GetComponentInParent <ICompilerCodeConnection>();

                        if (connection != null && func != null)
                        {
                            var con = connection.GetCodeConnection(hit).Value;

                            ICompilerCode afterCode = connection.CodeConnections[con.codeIndex];
                            if (afterCode != null)
                            {
                                lastCodeInMove.CodeConnections[0] = afterCode;
                                afterCode.Offset.Connection       = lastCodeInMove.CodeConnectionObjects[0];
                            }
                            connection.CodeConnections[con.codeIndex] = func;
                            func.Offset.Connection = connection.CodeConnectionObjects[con.codeIndex];

                            currentClonedObject.SetParent(currentScriptObject, false);
                            currentClonedObject = null;
                            ReconnectAll();
                        }
                    }
                    else
                    {
                        if (!canDropCode)
                        {
                            var           prevConCode = (CodeCon)previousConnection;
                            ICompilerCode afterCode   = prevConCode.con.CodeConnections[prevConCode.index];
                            if (afterCode != null)
                            {
                                lastCodeInMove.CodeConnections[0] = afterCode;
                                afterCode.Offset.Connection       = lastCodeInMove.CodeConnectionObjects[0];
                            }

                            prevConCode.con.CodeConnections[prevConCode.index] = func;
                            func.Offset.Connection = prevConCode.con.CodeConnectionObjects[prevConCode.index];

                            currentClonedObject.SetParent(currentScriptObject, false);
                            currentClonedObject = null;
                            ReconnectAll();
                        }
                        else
                        {
                            currentClonedObject.SetParent(otherCodeTransform);
                            currentClonedObject = null;
                            ReconnectOtherCode();
                        }
                    }

                    break;



                case CodeType.Value:
                    var val         = currentClonedObject.GetComponent <ICompilerValue>();
                    var connectPrev = true;

                    if (hit)
                    {
                        var connection = hit.GetComponentInParent <ICompilerValues>();

                        if (connection != null && val != null)
                        {
                            var con = connection.GetValue(hit).Value;

                            ICompilerValue oldValue = connection.Values[con.valueIndex];
                            if (oldValue != null)
                            {
                                connectPrev = true;
                            }
                            else
                            {
                                connection.Values[con.valueIndex] = val;
                                val.Offset.Connection             = con.connectObject;

                                currentClonedObject.SetParent(hit, false);
                                currentClonedObject = null;
                                ReconnectAll();

                                connectPrev = false;
                            }
                        }
                    }

                    if (connectPrev)
                    {
                        if (!canDropCode)
                        {
                            var prevCodeCon = (ValueCon)previousConnection;
                            prevCodeCon.con.Values[prevCodeCon.index] = val;
                            val.Offset.Connection = prevCodeCon.lastCon;

                            currentClonedObject.SetParent(prevCodeCon.lastCon, false);
                            currentClonedObject = null;
                            ReconnectAll();
                        }
                        else
                        {
                            currentClonedObject.SetParent(otherCodeTransform);
                            currentClonedObject = null;
                        }
                    }

                    ReconnectOtherCode();

                    break;
                }

                //clickAudioSource.Play();
            }

            //if (hit != null && hit.IsChildOf(otherCodeTransform))
            //ReconnectOtherCode();
        }
Example #7
0
 public CodeValue(int valueIndex, Transform connectObject, ICompilerValue value)
 {
     this.valueIndex    = valueIndex;
     this.connectObject = connectObject;
     this.value         = value;
 }