Ejemplo n.º 1
0
 public static EActor[] ToArray(SearchTreeMark[] stm)
 {
     EActor[] result = new EActor[stm.Length];
     for (int i = 0; i < stm.Length; i++)
     {
         result[i] = stm[i].actor;
     }
     return(result);
 }
Ejemplo n.º 2
0
        private EActor FindActorParentInChildren(EActor target)
        {
            // DFS getting the parent
            // Search all scene
            for (int i = 0; i < EEngine.instance.loadScene.Count; i++)
            {
                EScene sceneBuffer = EEngine.instance.loadScene[i];
                if (sceneBuffer == null)
                {
                    continue;
                }

                // If scene have one more root objects
                if (sceneBuffer.childLength > 0)
                {
                    // Loop each object in scene root
                    for (int j = 0; j < sceneBuffer.GetChild(j).childLength; j++)
                    {
                        EActor current = sceneBuffer.GetChild(j);

                        // If the target is exist in the looping child
                        if (current.ExistInChild(target))
                        {
                            // Get the path to the target
                            EActor[] path = current.GetPathToChild(target);

                            for (int k = 0; k < path.Length; k++)
                            {
                                // Previous one is the parent
                                if (path[k] == target)
                                {
                                    return(path[k - 1]);
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public static EScene GetDefaultScene()
        {
            EMaterial e = new EColorMat();
            // Empty scene
            EScene buffer = new EScene();

            // Add render stuff 03
            EActor obj = new EActor("floor");

            obj.position = new Vector3(0, -0.1f, 0);
            obj.scale    = new Vector3(20f, 20f, 20f);

            EMeshFilter meshf = obj.AddComponent <EMeshFilter>();

            meshf.SetMesh(EPrimitiveMesh.GetPrimitiveMesh(EPrimitiveMesh.PrimitiveType.Plane));

            EMeshRenderer meshr = obj.AddComponent <EMeshRenderer>();

            meshr.SetMaterial(e);
            buffer.AddActorToScene(obj);

            return(buffer);
        }
Ejemplo n.º 4
0
 public SearchTreeMark(EActor actor, int attempt)
 {
     this.actor   = actor;
     this.attempt = attempt;
 }
Ejemplo n.º 5
0
        public EActor[] GetPathToChild(EActor target)
        {
            if (!ExistInChild(target))
            {
                return(null);
            }

            bool Last = false;
            // The target eactor and the amount of path has attempt
            List <SearchTreeMark> memory = new List <SearchTreeMark>();

            memory.Add(new SearchTreeMark(this, 0));
            bool traceBack = false;

            while (!Last)
            {
                EActor current = memory[memory.Count - 1].actor;

                if (!traceBack)
                {
                    if (current.childLength == 0)
                    {
                        // Leaf
                        // Start traceback
                        traceBack = true;
                    }
                    else if (current.childLength == 1)
                    {
                        // single path
                        memory[memory.Count - 1].attempt++;
                        memory.Add(new SearchTreeMark(current.GetChild(0), 0));
                        if (current.GetChild(0) == target)
                        {
                            return(SearchTreeMark.ToArray(memory.ToArray()));
                        }
                    }
                    else if (current.childLength >= 2)
                    {
                        // mark point
                        memory[memory.Count - 1].attempt++;
                        int att = memory[memory.Count - 1].attempt;
                        memory.Add(new SearchTreeMark(current.GetChild(att - 1), 0));
                        if (current.GetChild(0) == target)
                        {
                            return(SearchTreeMark.ToArray(memory.ToArray()));
                        }
                    }
                }
                else
                {
                    memory.RemoveAt(memory.Count - 1);

                    for (int i = memory.Count - 1; i >= 0; i--)
                    {
                        if (memory[i].actor.childLength > memory[i].attempt)
                        {
                            // need more attempt
                            traceBack = false;
                        }
                        else
                        {
                            memory.RemoveAt(i);
                        }
                    }

                    if (memory.Count == 0 && memory[memory.Count - 1].attempt == memory[memory.Count - 1].actor.childLength)
                    {
                        Last = true;
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 6
0
 public void SetLastChild(EActor target)
 {
     children.Add(target);
 }
Ejemplo n.º 7
0
 public void SetFirstChild(EActor target)
 {
     children.Insert(0, target);
 }
Ejemplo n.º 8
0
 public void AddActorToScene(EActor actor)
 {
     gameObjects.Add(actor);
 }