Esempio n. 1
0
        static void Main(string[] args)
        {
            IArray array = new NodeArray();

            Console.WriteLine(array.ToString());

            array.AddAtPosition(1, 0);
            Console.WriteLine(array.ToString());

            array.AddAtPosition(2, 0);
            Console.WriteLine(array.ToString());

            array.AddAtPosition(3, 0);
            Console.WriteLine(array.ToString());

            array.AddAtPosition(4, 1);
            Console.WriteLine(array.ToString());

            array.AddAtPosition(5, 3);
            Console.WriteLine(array.ToString());

            array.AddAtPosition(6, 4);
            Console.WriteLine(array.ToString());

            array.AddAtPosition(0, 6);
            Console.WriteLine(array.ToString());

            array.Add(1);
            array.Add(6);
            array.Add(5);
            array.Add(2);
            array.Add(4);
            array.Add(3);
            Console.WriteLine(array.ToString());

            array.Remove(10);
            Console.WriteLine(array.ToString());

            array.Remove(1);
            Console.WriteLine(array.ToString());

            array.RemoveAtPosition(6);
            Console.WriteLine(array.ToString());

            array.Clear();
            Console.WriteLine(array.ToString());

            array.Add(1);
            array.Add(2);
            array.Add(3);
            array.Add(4);
            array.Add(5);
            Console.WriteLine(array.ToString());

            array.Reverse();
            Console.WriteLine(array.ToString());
        }
Esempio n. 2
0
 /// <summary>
 /// Removes the subnode with the given key. Can only be called on array nodes.
 /// </summary>
 /// <param name="key">Key of the subnode to remove</param>
 /// <returns>True if node was removed, false if not found</returns>
 public bool RemoveSubnode(string key)
 {
     if (NodeType != ValueType.Array)
     {
         return(false);
     }
     return(NodeArray.Remove(key));
 }
Esempio n. 3
0
        /// <summary>
        ///     Removes any array nodes without any value-type children
        /// </summary>
        public void CleanTree()
        {
            Dictionary <string, VdfFileNode> nodes = NodeArray;

            if (nodes != null)
            {
                string[] keys = nodes.Keys.ToArray();
                foreach (string key in keys)
                {
                    nodes[key].CleanTree();
                    if (nodes[key].IsEmpty())
                    {
                        NodeArray.Remove(key);
                    }
                }
            }
        }
Esempio n. 4
0
    public IEnumerator Colorize(NodeArray list)
    {
        yield return(null);

        float waitTime = 0;

        while (list.Count > 0)
        {
            if (waitTime > 2)
            {
                var node = list[0];
                node.GetComponentInChildren <MeshRenderer>().material.color = Eval(node.getWeight());
                list.Remove(node);

                yield return(new WaitForSecondsRealtime(2));

                waitTime = 0;
            }
            waitTime += Time.deltaTime;
        }
    }
Esempio n. 5
0
 public bool RemoveSubNode(string key)
 {
     return(NodeType == ValueType.Array && NodeArray.Remove(key));
 }
Esempio n. 6
0
 /// <summary>
 ///     Removes the subnode with the given key. Can only be called on array nodes.
 /// </summary>
 /// <param name="key">Key of the subnode to remove</param>
 /// <returns>True if node was removed, false if not found</returns>
 public bool RemoveSubnode(string key) => (NodeType == ValueType.Array) && NodeArray.Remove(key);
Esempio n. 7
0
    public static void PropagateInfluence(Node node, float strength, float team = 1)
    {
        float Normalize(float x)
        {
            return(x / strength);
        }

        //var hits = Physics.OverlapSphere(node.transform.position, strength);
        NodeArray open   = new NodeArray();
        NodeArray closed = new NodeArray();
        Dictionary <Node, float> weightList = new Dictionary <Node, float>();

        open.Add(node);
        float initWeight = node.getWeight();

        node.setWeight(team);

        Dictionary <Node, int> depthMap = new Dictionary <Node, int>();

        depthMap.Add(node, 0);

        while (open.Count > 0)
        {
            var myNode = open[0];
            open.Remove(myNode);
            if (!closed.Contains(myNode))
            {
                closed.Add(myNode);
            }

            var connections = GetConnections(myNode);

            foreach (Connection connection in connections)
            {
                if (!closed.Contains(connection.to) && Vector3.Distance(connection.to.transform.position, node.transform.position) < strength)
                {
                    int depth = depthMap[myNode] + 1;
                    depthMap[connection.to] = depth;
                    closed.Add(connection.to);
                    weightList.Add(connection.to, connection.to.getWeight());
                    if (!open.Contains(connection.to))
                    {
                        open.Add(connection.to);
                    }
                    connection.to.setWeight(myNode.getWeight() * Mathf.Pow(Mathf.Abs(Normalize(strength - (depth * myNode.NodeSizeMultiplier))), .5f));
                }
            }
        }

        node.setWeight(initWeight + node.getWeight());

        foreach (var myPair in weightList)
        {
            var myNode   = myPair.Key;
            var myWeight = myPair.Value;
            myNode.setWeight(myWeight + myNode.getWeight());
        }

        foreach (var myNode in closed)
        {
            if (!myNode)
            {
                continue;
            }
            myNode.Colorize(Eval(myNode.getWeight()));
        }

        //InputManager instance = FindObjectOfType<InputManager>();
        //instance.CallColorize(closed);

        //foreach (var hit in hits)
        //{
        //    Node myNode = hit.GetComponentInParent<Node>();
        //    if (!myNode) continue;
        //    myNode.setWeight( Normalize (strength - Mathf.Clamp(Vector3.Distance(myNode.transform.position, node.transform.position),0,strength)) * team + myNode.getWeight());
        //    hit.GetComponent<MeshRenderer>().material.color = Eval(myNode.getWeight());
        //}
    }