示例#1
0
        // creates any startup objects, returns null if no prefabs are assigned
        public bool ShowStartupObjects(bool tutorial)
        {
            GameObject startupObjects = infiniteObjectManager.CreateStartupObjects(tutorial);

            if (startupObjects == null)
            {
                return(false);
            }

            Transform      objectTypeParent;
            Transform      topObject;
            Transform      transformParent;
            InfiniteObject parentInfiniteObject;
            bool           isSceneObject;

            for (int i = 0; i < 2; ++i)
            {
                isSceneObject    = i == 0;
                objectTypeParent = startupObjects.transform.Find((isSceneObject ? "Scene" : "Platforms"));
                // iterate high to low because assignParent is going to set a new parent thus changing the number of children in startup objects
                for (int j = objectTypeParent.childCount - 1; j >= 0; --j)
                {
                    topObject = objectTypeParent.GetChild(j);
                    infiniteObjectManager.AssignParent(topObject.GetComponent <InfiniteObject>(), (isSceneObject ? ObjectType.Scene : ObjectType.Platform));

                    InfiniteObject[] childObjects;
                    if (isSceneObject)
                    {
                        childObjects = topObject.GetComponentsInChildren <SceneObject>() as SceneObject[];
                    }
                    else
                    {
                        childObjects = topObject.GetComponentsInChildren <PlatformObject>() as PlatformObject[];
                    }
                    for (int k = 0; k < childObjects.Length; ++k)
                    {
                        childObjects[k].EnableDestroyOnDeactivation();
                        transformParent = childObjects[k].GetTransform().parent;
                        if ((parentInfiniteObject = transformParent.GetComponent <InfiniteObject>()) != null)
                        {
                            childObjects[k].SetInfiniteObjectParent(parentInfiniteObject);
                        }

                        if (!isSceneObject)   // platform
                        {
                            PlatformObject platformObject = ((PlatformObject)childObjects[k]);
                            if (platformObject.leftTurn || platformObject.rightTurn)
                            {
                                turnPlatform[(int)ObjectLocation.Center] = platformObject;
                                turnIndex[(int)ObjectLocation.Center]    = infiniteObjectHistory.GetLastLocalIndex(ObjectLocation.Center, ObjectType.Platform);
                            }
                            // mark the coin objects as destructible so they get destroyed if they are collected
                            CoinObject[] coinObjects = platformObject.GetComponentsInChildren <CoinObject>() as CoinObject[];
                            for (int l = 0; l < coinObjects.Length; ++l)
                            {
                                coinObjects[l].EnableDestroyOnDeactivation();
                            }
                        }
                    }
                }
            }

            // Get the persistent objects
            InfiniteObjectPersistence persistence = startupObjects.GetComponent <InfiniteObjectPersistence>();

            infiniteObjectHistory.LoadInfiniteObjectPersistence(persistence);

            // All of the important objects have been taken out, destroy the game object
            Destroy(startupObjects.gameObject);

            return(true);
        }
    // creates any startup objects, returns null if no prefabs are assigned
    public bool showStartupObjects(bool tutorial)
    {
        GameObject startupObjects = infiniteObjectManager.createStartupObjects(tutorial);

        if (startupObjects == null)
        {
            return(false);
        }

        ObjectLocation location;
        Transform      objectTypeParent;
        Transform      parentObject;
        Transform      transformParent;
        InfiniteObject parentInfiniteObject;
        bool           isSceneObject;

        for (int i = 0; i < 2; ++i)
        {
            isSceneObject    = i == 0;
            objectTypeParent = startupObjects.transform.FindChild((isSceneObject ? "Scene" : "Platforms"));
            // iterate high to low because assignParent is going to move set a new parent thus changing the number of children in startup objects
            for (int j = objectTypeParent.childCount - 1; j >= 0; --j)
            {
                parentObject = objectTypeParent.GetChild(j);

                // determine the direction the object is facing based off of the y angle
                float yAngle = parentObject.eulerAngles.y;
                if (yAngle > 360 || yAngle < 0)
                {
                    yAngle = yAngle % 360;
                }

                if (yAngle > 269)
                {
                    location = ObjectLocation.Left;
                }
                else if (yAngle > 89)
                {
                    location = ObjectLocation.Right;
                }
                else
                {
                    location = ObjectLocation.Center;
                }

                infiniteObjectHistory.setTopInfiniteObject(location, isSceneObject, parentObject.GetComponent <InfiniteObject>());
                infiniteObjectManager.assignParent(parentObject.GetComponent <InfiniteObject>(), (isSceneObject ? ObjectType.Scene : ObjectType.Platform));

                InfiniteObject[] childObjects;
                if (isSceneObject)
                {
                    childObjects = parentObject.GetComponentsInChildren <SceneObject>() as SceneObject[];
                }
                else
                {
                    childObjects = parentObject.GetComponentsInChildren <PlatformObject>() as PlatformObject[];
                }
                for (int k = 0; k < childObjects.Length; ++k)
                {
                    childObjects[k].enableDestroyOnDeactivation();
                    transformParent = childObjects[k].getTransform().parent;
                    if ((parentInfiniteObject = transformParent.GetComponent <InfiniteObject>()) != null)
                    {
                        childObjects[k].setInfiniteObjectParent(parentInfiniteObject);
                    }

                    // If there are no infinite objects under the current object, it is the last object in the hierarchy
                    if ((isSceneObject && childObjects[k].GetComponentsInChildren <SceneObject>().Length == 1) ||
                        (!isSceneObject && childObjects[k].GetComponentsInChildren <PlatformObject>().Length == 1))
                    {
                        infiniteObjectHistory.setBottomInfiniteObject(location, isSceneObject, childObjects[k].GetComponent <InfiniteObject>());
                    }

                    if (!isSceneObject)   // platform
                    {
                        PlatformObject platformObject = ((PlatformObject)childObjects[k]);
                        if (platformObject.isLeftTurn || platformObject.isRightTurn)
                        {
                            turnPlatform[(int)ObjectLocation.Center] = platformObject;
                        }
                        // mark the coin objects as destructible so they get destroyed if they are collected
                        CoinObject[] coinObjects = platformObject.GetComponentsInChildren <CoinObject>() as CoinObject[];
                        for (int l = 0; l < coinObjects.Length; ++l)
                        {
                            coinObjects[l].enableDestroyOnDeactivation();
                        }
                    }
                }
            }
        }

        // Get the persistent objects
        InfiniteObjectPersistence persistence = startupObjects.GetComponent <InfiniteObjectPersistence>();

        infiniteObjectHistory.loadInfiniteObjectPersistence(persistence);
        loadInfiniteObjectPersistence(persistence);

        // All of the important objects have been taken out, destroy the game object
        Destroy(startupObjects.gameObject);

        return(true);
    }