Exemplo n.º 1
0
        private Vector3 FromNode(PlatformNode p0, MapDirections direction)
        {
            Vector3 off = Vector3.zero;

            switch (direction)
            {
            case MapDirections.North:
                off = new Vector3(0, height, offset);
                break;

            case MapDirections.South:
                off = new Vector3(0, height, -offset);
                break;

            case MapDirections.East:
                off = new Vector3(offset, height, 0);
                break;

            case MapDirections.West:
                off = new Vector3(-offset, height, 0);
                break;
            }

            return(p0.transform.localPosition + off);
        }
Exemplo n.º 2
0
        public PlatformNode GetPlatformAfterMovement()
        {
            PlatformNode tmpNext = null;

            if (currentNode is SpawnerNode)
            {
                SpawnerNode c = currentNode as SpawnerNode;
                tmpNext = c.forwardNode;
            }
            else
            {
                PlatformNode bn          = currentNode as PlatformNode;
                Vector2Int   coordinates = bn.Coordinates;
                foreach (MovementOptions currentMovement in movementPattern.moves)
                {
                    Vector2Int delta = currentMovement == MovementOptions.Forward
                        ? facing.DirectionsDelta()
                        : facing.GetNeighbor(currentMovement == MovementOptions.Left).DirectionsDelta();

                    coordinates = coordinates + delta;
                    tmpNext     = Board.GetPlatform(coordinates);
                }
            }

            return(tmpNext);
        }
Exemplo n.º 3
0
 public PlatformNode GetPlatform(Vector2Int coord)
 {
     try {
         PlatformNode pn = Platforms[coord.x][coord.y];
         return(pn);
     }
     catch (IndexOutOfRangeException) {
         return(null);
     }
 }
Exemplo n.º 4
0
        public virtual void Move()
        {
            PlatformNode tmpNext = GetPlatformAfterMovement();

            if (tmpNext)
            {
                StartCoroutine(JumpTo(tmpNext));
                currentNode = tmpNext;
                onNodeChange.Invoke(tmpNext);
            }
        }
Exemplo n.º 5
0
 public void HighlightFromProxy(ProxyBoard proxy)
 {
     for (int i = 0; i < proxy.Length; i++)
     {
         for (int j = 0; j < proxy.Length; j++)
         {
             PlatformNode b = Platforms[i][j];
             b.Highlight(proxy[i][j]);
         }
     }
 }
Exemplo n.º 6
0
        private void SetSpawnNodes()
        {
            GameObject pgo = new GameObject();

            pgo.transform.position = transform.position;
            Transform parent = pgo.transform;

            parent.parent = transform;

            parent.name = "Spawner Nodes";
            //Horizontal
            for (int i = 0; i < mapSize; i++)
            {
                PlatformNode forwardNode = Platforms[i][0];
                SpawnerNode  sn          = Instantiate(spawnerPrefab, parent, true);
                sn.transform.position = forwardNode.landingPosition.transform.position + Vector3.back * spacing;
                sn.transform.name     = $"SN: {i}-0";
                sn.forwardNode        = forwardNode;
                sn.forwardDirection   = MapDirections.North;
                spawnerNodes.Add(sn);

                forwardNode           = Platforms[i][mapSize - 1];
                sn                    = Instantiate(spawnerPrefab, parent, true);
                sn.transform.position = forwardNode.landingPosition.transform.position + Vector3.forward * spacing;
                sn.transform.name     = $"SN: {i}-{mapSize - 1}";
                sn.forwardNode        = forwardNode;
                sn.forwardDirection   = MapDirections.South;
                spawnerNodes.Add(sn);
            }


            //Vertical
            for (int i = 0; i < mapSize; i++)
            {
                PlatformNode forwardNode = Platforms[0][i];
                SpawnerNode  sn          = Instantiate(spawnerPrefab, parent, true);
                sn.transform.position = forwardNode.landingPosition.transform.position + Vector3.left * spacing;
                sn.transform.name     = $"SN: {0}-{i}";
                sn.forwardNode        = forwardNode;
                sn.forwardDirection   = MapDirections.East;
                spawnerNodes.Add(sn);


                forwardNode           = Platforms[mapSize - 1][i];
                sn                    = Instantiate(spawnerPrefab, parent, true);
                sn.transform.position = forwardNode.landingPosition.transform.position + Vector3.right * spacing;
                sn.transform.name     = $"SN: {mapSize - 1}-{i}";
                sn.forwardDirection   = MapDirections.West;
                sn.forwardNode        = forwardNode;
                spawnerNodes.Add(sn);
            }
        }
Exemplo n.º 7
0
    private void OnSceneGUI()
    {
        //Handles.PositionHandle(transform.position, Quaternion.identity);
        Vector3 lastNodePos = transform.position;

        for (int i = 0; i < platform.nodes.Count; i++)
        {
            PlatformNode node = platform.nodes[i];

            Vector3 wPos = transform.TransformPoint(node.position);
            Vector3 nPos = Handles.PositionHandle(wPos, Quaternion.identity);
            node.position = transform.InverseTransformPoint(nPos);


            Handles.DrawDottedLine(lastNodePos, nPos, 10);
            lastNodePos = nPos;
        }
        PreviewPlatform();
        EditorUtility.SetDirty(target);
    }
Exemplo n.º 8
0
        protected IEnumerator JumpTo(PlatformNode tmpNext)
        {
            canMove = false;
            float   time  = 0f;
            Vector3 start = transform.position;
            Vector3 end   = tmpNext.landingPosition.position;

            while (time < JumpDuration)
            {
                time += Time.deltaTime;


                float linearT = time / JumpDuration;
                float heightT = curve.Evaluate(linearT);

                float height = Mathf.Lerp(0f, jumpHeight, heightT); // change 3 to however tall you want the arc to be

                transform.position = Vector3.Lerp(start, end, linearT) + Vector3.up * height;

                yield return(null);
            }
        }
Exemplo n.º 9
0
        private void SpawnPlatforms()
        {
            GameObject pgo = new GameObject();

            pgo.transform.position = transform.position;

            Transform parent = pgo.transform;

            parent.parent = transform;
            parent.name   = "Platform Nodes";
            for (int x = 0; x < mapSize; x++)
            {
                Platforms[x] = new PlatformNode[mapSize];
                for (int y = 0; y < mapSize; y++)
                {
                    PlatformNode board = Instantiate(boardPrefab, parent, true);
                    board.transform.position = new Vector3(x * spacing, transform.position.y, y * spacing);
                    board.transform.name     = $"Node: {x}-{y}";
                    board.Coordinates        = new Vector2Int(x, y);
                    Platforms[x][y]          = board;
                }
            }
        }
Exemplo n.º 10
0
 public void AddNode(PlatformNode node)
 {
     neibors.Add(node);
 }
Exemplo n.º 11
0
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        EditorGUI.BeginChangeCheck();
        bool startMove = EditorGUILayout.Toggle("Move on start", platform.moveOnStart);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(target, "Changed Moving Platform action");
            platform.moveOnStart = startMove;
        }

        EditorGUI.BeginChangeCheck();
        PlatformMovingKind kind = (PlatformMovingKind)EditorGUILayout.EnumPopup("Looping", platform.kind);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(target, "Changed Moving Platform type");
            platform.kind = kind;
        }

        EditorGUI.BeginChangeCheck();
        float newSpeed = EditorGUILayout.FloatField("Speed", platform.speed);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(target, "Changed Speed");
            platform.speed = newSpeed;
        }

        EditorGUI.BeginChangeCheck();
        platform.platform = EditorGUILayout.ObjectField("Platform", platform.platform, typeof(Transform), true) as Transform;
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(target, "Changed platform");
        }

        EditorGUILayout.Separator();

        int delete = -1;

        nodesFold = EditorGUILayout.Foldout(nodesFold, "Nodes");
        if (nodesFold)
        {
            EditorGUILayout.BeginVertical("Textfield");

            EditorGUILayout.LabelField("Node 0");

            EditorGUILayout.BeginHorizontal("Box");
            EditorGUILayout.LabelField("", GUILayout.Width(5));
            EditorGUI.BeginChangeCheck();
            float fDelay = EditorGUILayout.FloatField("Wait Time", platform.zeroDelay);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Changed zero delay");
                platform.zeroDelay = fDelay;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            for (int i = 0; i < platform.nodes.Count; i++)
            {
                EditorGUI.BeginChangeCheck();
                PlatformNode node = platform.nodes[i];

                EditorGUILayout.BeginVertical("Textfield");

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Node " + (i + 1).ToString() + "   " + string.Format("x:{0:0.000} y:{1:0.000}", node.position.x, node.position.y));
                if (GUILayout.Button("Delete", GUILayout.Width(50)))
                {
                    delete = i;
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal("Box");

                EditorGUILayout.LabelField("", GUILayout.Width(5));
                float wDelay = EditorGUILayout.FloatField("Wait Time", node.waitOnNode);

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(target, "Changed node " + i);
                    node.waitOnNode = wDelay;
                }
            }
        }

        Vector3 last = platform.nodes.Count > 0 ? platform.nodes[platform.nodes.Count - 1].position : Vector3.zero;

        if (GUILayout.Button("Add Node"))
        {
            Undo.RecordObject(target, "added node");
            last += Vector3.up;
            platform.nodes.Add(new PlatformNode()
            {
                position = last
            });
        }

        testSlider = EditorGUILayout.Slider("Preview position", testSlider, 0.0f, 1.0f);
        PreviewPlatform();

        if (delete > -1)
        {
            Undo.RecordObject(target, "Delete node " + delete);
            platform.nodes.RemoveAt(delete);
        }
        EditorUtility.SetDirty(target);
    }
Exemplo n.º 12
0
 private void InteractWithNode(PlatformNode node)
 {
     node.ActivateSpecialEffect(this);
 }