예제 #1
0
 void FillPool()
 {
     prefabPool = new Queue <GroundBase>();
     for (int i = 0; i < poolSize; i++)
     {
         GroundBase ground = Instantiate(groundPrefab);
         ground.gameObject.SetActive(false);
         ground.transform.parent = enivromentParent;
         prefabPool.Enqueue(ground);
     }
 }
예제 #2
0
 GroundBase GetNewGround()
 {
     if (prefabPool.Count <= 0)
     {
         GroundBase ground = Instantiate(groundPrefab);
         ground.gameObject.SetActive(false);
         ground.transform.parent = enivromentParent;
         return(ground);
     }
     else
     {
         return(prefabPool.Dequeue());
     }
 }
예제 #3
0
    void Update()
    {
        Vector3 playerPos = PlayerManager.Instance.player.transform.position;

        while (lastGroundPos + groundSize * 0.5f < playerPos.z + endOffset)
        {
            lastGroundPos = Mathf.Max(lastGroundPos, playerPos.z - startOffset);

            GroundBase ground = GetNewGround();
            activeGrounds.Add(ground);
            ground.gameObject.SetActive(true);
            ground.transform.position = new Vector3(0, playerPos.y, lastGroundPos + groundSize * 0.5f);

            lastGroundPos += groundSize;
        }
    }
예제 #4
0
    public override void OnInspectorGUI()
    {
        EditorTools.TitleField("地板編輯工具");
        Undo.RecordObject(target, "Modified Path");

        Ferr2D_Path path = (Ferr2D_Path)target;

        // if this was an undo, refresh stuff too
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":

                path.UpdateDependants(true);
                if (OnChanged != null)
                {
                    OnChanged();
                }
                return;
            }
        }

        path.closed = EditorGUILayout.Toggle("封閉地面", path.closed);
        if (path)
        {
            // display the path verts list info
            showVerts = EditorGUILayout.Foldout(showVerts, "頂點座標");
        }
        EditorGUI.indentLevel = 2;
        if (showVerts)
        {
            int size = EditorGUILayout.IntField("數量: ", path.pathVerts.Count);
            while (path.pathVerts.Count > size)
            {
                path.pathVerts.RemoveAt(path.pathVerts.Count - 1);
            }
            while (path.pathVerts.Count < size)
            {
                path.pathVerts.Add(new Vector2(0, 0));
            }
        }
        // draw all the verts! Long list~
        for (int i = 0; showVerts && i < path.pathVerts.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("#" + i, GUILayout.Width(60));
            path.pathVerts[i] = new Vector2(
                EditorGUILayout.FloatField(path.pathVerts[i].x),
                EditorGUILayout.FloatField(path.pathVerts[i].y));
            EditorGUILayout.EndHorizontal();
        }

        // button for updating the origin of the object

        if (GUILayout.Button("座標重置"))
        {
            path.ReCenter();
        }

        bool updateClosed           = false;
        Ferr2DT_PathTerrain terrain = path.GetComponent <Ferr2DT_PathTerrain>();

        if (!path.closed && terrain != null && (terrain.fill == Ferr2DT_FillMode.Closed || terrain.fill == Ferr2DT_FillMode.InvertedClosed || terrain.fill == Ferr2DT_FillMode.FillOnlyClosed))
        {
            path.closed  = true;
            updateClosed = true;
        }
        if (terrain != null && path.closed && (terrain.fill == Ferr2DT_FillMode.FillOnlySkirt || terrain.fill == Ferr2DT_FillMode.Skirt))
        {
            path.closed  = false;
            updateClosed = true;
        }

        // update dependants when it changes
        if (GUI.changed || updateClosed)
        {
            path.UpdateDependants(false);
            EditorUtility.SetDirty(target);
        }

        sizeX = EditorTools.IntField(sizeX, "寬");
        sizeY = EditorTools.IntField(sizeY, "長");

        if (GUILayout.Button("地板格式化"))
        {
            path.pathVerts = new List <Vector2>();
            path.pathVerts.Add(new Vector2(sizeX, sizeY) * 0.5F);
            path.pathVerts.Add(new Vector2(sizeX, -sizeY) * 0.5F);
            path.pathVerts.Add(new Vector2(-sizeX, -sizeY) * 0.5F);
            path.pathVerts.Add(new Vector2(-sizeX, sizeY) * 0.5F);
            UpdateDependentsSmart(path, false, false);
            EditorUtility.SetDirty(target);
            prevChanged = true;

            BoxCollider2D box2D = path.GetComponent <BoxCollider2D>();
            if (box2D)
            {
                path.GetComponent <BoxCollider2D>().size = new Vector2(sizeX, sizeY);
                EditorUtility.SetDirty(path.GetComponent <BoxCollider2D>());
            }
        }

        if (GUILayout.Button("進階地板設定"))
        {
            GroundBase groundBase = path.GetComponent <GroundBase>();
            if (!groundBase)
            {
                path.gameObject.AddComponent <GroundBase>();
            }
        }

        EditorTools.Mig();
    }
예제 #5
0
 public void FreeGroundInstance(GroundBase ground)
 {
     ground.gameObject.SetActive(false);
     prefabPool.Enqueue(ground);
     activeGrounds.Remove(ground);
 }