Exemple #1
0
        public T Load <T>(string name, string path) where T : UnityEngine.Object
        {
            T res = null;

            try
            {
                res = GetAsset <T>(name);

                if (AFObject.IsNull(res))
                {
                    if (typeof(T) == typeof(AFTextureAtlas))
                    {
                        res = Add(name, new AFTextureAtlas(name, path, AFTextureAtlas.EFileType.kTextTypes_Csv)) as T;
                    }
                    else
                    {
                        res = Resources.Load <T>(path);

                        if (typeof(T) == typeof(Texture))
                        {
                            Add(name, res as Texture);
                        }

                        else if (typeof(T) == typeof(GameObject))
                        {
                            Add(name, res as GameObject);
                        }

                        else if (typeof(T) == typeof(AFSound))
                        {
                            Add(name, res as AFSound);
                        }

                        else if (typeof(T) == typeof(Texture))
                        {
                            Add(name, res as Texture);
                        }
                        else
                        {
                            Add(name, res);
                        }

                        Resources.UnloadUnusedAssets();
                    }

                    UnityEngine.Debug.Log("I'll store an object of: " + typeof(T).ToString());
                }
            }
            catch (NullReferenceException nullEx)
            {
                UnityEngine.Debug.LogError("The asset was not found: " + nullEx.Message);
            }
            catch (Exception ex)
            {
                //TODO: Discover what happens when unity throw this error
                UnityEngine.Debug.LogError("The asset was not found: " + ex.Message);
            }

            return(res);
        }
Exemple #2
0
        public GameObject Add(string name, GameObject gameObject)
        {
            if (!AFObject.IsNull(gameObject))
            {
                m_prefabs.Add(name, gameObject);
            }
            else
            {
                UnityEngine.Debug.LogWarning("GameObject could not be null");
            }

            return(gameObject);
        }
Exemple #3
0
        public Texture Add(string name, Texture texture)
        {
            if (!AFObject.IsNull(texture))
            {
                m_textures.Add(name, texture);
            }
            else
            {
                UnityEngine.Debug.LogWarning("Texture could not be null");
            }

            return(texture);
        }
Exemple #4
0
        public AFSound Add(string name, AFSound sound)
        {
            if (!AFObject.IsNull(sound))
            {
                m_sounds.Add(name, sound);
            }
            else
            {
                UnityEngine.Debug.LogWarning("AFSound could not be null");
            }

            return(sound);
        }
Exemple #5
0
        public object Add(string name, object obj)
        {
            if (!AFObject.IsNull(obj))
            {
                m_custom.Add(name, obj);
            }
            else
            {
                UnityEngine.Debug.LogWarning("Object could not be null");
            }

            return(obj);
        }
Exemple #6
0
        public AFTextureAtlas Add(string name, AFTextureAtlas obj)
        {
            if (!AFObject.IsNull(obj))
            {
                m_texturesAtlas.Add(name, obj);
            }
            else
            {
                UnityEngine.Debug.LogWarning("TextureAtlas could not be null");
            }

            return(obj);
        }
Exemple #7
0
        override public void AFDestroy()
        {
            m_stateManger  = null;
            m_soundManager = null;
            m_assetManager = null;
            m_input        = null;
            m_engine       = null;

            for (int i = 0; i < m_objects.Count; ++i)
            {
                m_objects[i].AFDestroy();
            }

            for (int i = 0; i < m_gameObjects.Count; ++i)
            {
                if (AFObject.IsNull(m_gameObjects[i]))
                {
                    Destroy(m_gameObjects[i]);
                }
            }

            m_objects.Clear();
            m_objects = null;

            OnStart.RemoveAll();
            OnStart = null;

            OnDestroy.RemoveAll();
            OnDestroy = null;

            OnInitialized.RemoveAll();
            OnInitialized = null;

            OnPause.RemoveAll();
            OnPause = null;

            OnObjectAdded.RemoveAll();
            OnObjectAdded = null;

            OnObjectRemoved.RemoveAll();
            OnObjectRemoved = null;

            base.AFDestroy();
        }
Exemple #8
0
        public T Instantiate <T>(string nameOrPath) where T : UnityEngine.Object
        {
            T L_object = Load <T>(nameOrPath);

            if (AFObject.IsNull(L_object))
            {
                AFDebug.LogError("Was not Possible to load or instantiate follow gameObject: " + name);
            }
            else
            {
                T L_objectInstantiated = Instantiate(L_object) as T;

                if (AFObject.IsNull(L_object))
                {
                    AFDebug.LogError("Was not Possible to load or instantiate follow gameObject: " + name);
                }

                return(L_objectInstantiated);
            }

            return(null);
        }
Exemple #9
0
        public void AddTrasitionView(GameObject transitionGO)
        {
            m_trasition           = transitionGO;
            m_updatableComponents = m_trasition.GetComponents <AFObject>();
            //Todo: IMPLEMENT MULTHREAD

            SpriteRenderer[] spRenderer = m_trasition.GetComponents <SpriteRenderer>();

            for (int i = 0; i < spRenderer.Length; ++i)
            {
                if (!AFObject.IsNull(spRenderer[i]))
                {
                    spRenderer[i].sortingOrder = SPRITE_SORT_LAYER;
                }
            }

            if (m_updatableComponents.Length > 0)
            {
                CreateThread();
            }

            Hide();
        }
Exemple #10
0
        virtual public AFObject Add(AFObject obj)
        {
            AFObject L_object = GetObjectByName(obj.name);

            if (AFObject.IsNull(L_object))
            {
                L_object = obj;
                m_objects.Add(L_object);
                L_object.gameObject.transform.parent = this.gameObject.transform;

                //Add(L_object.gameObject);
            }
            else
            {
                UnityEngine.Debug.LogWarning("The object already in the State: " + L_object.name);
            }

            if (m_hasEvents)
            {
                OnObjectAdded.Dispatch(L_object);
            }

            return(L_object);
        }
Exemple #11
0
        public override void BuildState()
        {
#if UNITY_EDITOR
            AFAssetManager.SimulatedDPI     = AFAssetManager.DPI_IPHONE_4_5;
            AFAssetManager.SimulatePlatform = AFAssetManager.EPlataform.IOS;
#endif
            _cameraGameObject      = new GameObject();
            _cameraGameObject.name = "StateCam";
            m_camera = _cameraGameObject.AddComponent <MyCamera>().GetCamera();

            string path = AFAssetManager.GetPathTargetPlatform() + "Prefabs/StartSceneCanvas";

            AFDebug.Log(AFAssetManager.GetPathTargetPlatform() + "Prefabs/StartScene");

            GameObject startSceneToIntantiate = AFAssetManager.Instance.Load <GameObject>(path);

            if (!AFObject.IsNull(startSceneToIntantiate))
            {
                m_interface = AFAssetManager.Instance.Instantiate <GameObject>(path);

                if (!AFObject.IsNull(m_interface))
                {
                    Canvas L_canvas = m_interface.GetComponent <Canvas>();

                    if (!AFObject.IsNull(L_canvas))
                    {
                        L_canvas.renderMode  = RenderMode.ScreenSpaceCamera;
                        L_canvas.worldCamera = m_camera;
                    }
                    else
                    {
                        AFDebug.LogError("Canvas not found!");
                    }

                    _background  = GameObject.Find("Background");
                    _startButton = GameObject.Find("StartButton");

                    path = AFAssetManager.GetPathTargetPlatformWithResolution("Scenes/StartScene/Background");
                    AFDebug.Log(path);
                    Sprite L_sprite = AFAssetManager.Instance.Load <Sprite>(path);
                    _background.GetComponent <Image>().sprite = L_sprite;


                    path     = AFAssetManager.GetPathTargetPlatformWithResolution("Scenes/StartScene/StartButton");
                    L_sprite = AFAssetManager.Instance.Load <Sprite>(path);
                    AFDebug.Log(path);
                    _startButton.GetComponent <Image>().sprite = L_sprite;

                    _startButton.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(() => { OnClick(); });
                }
                else
                {
                    AFDebug.LogError("Nao foi possivel encontrar a interface do login");
                }
            }
            else
            {
                AFDebug.LogError("Nao foi possivel encontrar a interface do login para clonar");
            }


            Add(m_interface);

            base.BuildState();
        }