コード例 #1
0
    protected void Awake()
    {
        if (instance != null)
        {
            Destroy(gameObject);
            return;
        }

        instance = this;

        // Has to be in root hierarchy for DontDestroyOnLoad
        if (transform.parent != null)
        {
            transform.parent = null;
        }
        DontDestroyOnLoad(gameObject);

        _timeScale            = new Combinder <float>((float prevVal, float newVal) => Mathf.Min(prevVal, newVal), defaultVal: 1.0f);
        _timeScale.onChanged += OnTimeScaleChanged;

        StartCoroutine(PostRenderRoutine());

        try
        {
            AtAwake();
        }
        catch (Exception exc)
        {
            Dbg.LogExcRelease(this, exc);
            Dbg.LogErrorRelease(this, "APP: Awake failed");
            UE.Debug.Break();
        }
    }
コード例 #2
0
    IEnumerator OnSceneLoadedRoutine()
    {
        Dbg.LogRelease(this, "APP: Scene loaded");

        while (!readyForSceneLoad)
        {
            yield return(null);
        }

        Scene activeScene = SceneManager.GetActiveScene();

        if (activeScene.name == splashSceneName)
        {
            Dbg.LogRelease(this, "APP: Scene was splash");

            // Null here already because after this we're done
            setupRoutine = null;

            for (int buildIndex = 0; buildIndex < SceneManager.sceneCountInBuildSettings; ++buildIndex)
            {
                string sceneName      = Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(buildIndex));
                bool   validSceneName =
                    !string.IsNullOrEmpty(sceneName) &&
                    sceneName != loadingSceneName &&
                    sceneName != splashSceneName
                ;
                if (validSceneName)
                {
                    Dbg.LogRelease(this, "APP: Found first scene \"{0}\"", sceneName);
                    LoadScene(sceneName);
                    yield break;
                }
            }

            Dbg.LogErrorRelease(this, "APP: Did not find a first scene to load");
            yield break;
        }

        Dbg.LogRelease(this, "APP: Disabling Gravity");
        Vector3 gravityToRestore = Physics.gravity;

        Physics.gravity = Vector3.zero;

        try
        {
            FindAndSetupState();
        }
        catch (Exception exc)
        {
            Dbg.LogExcRelease(exc);
            Dbg.LogErrorRelease(this, "APP: State setup failed");

            UE.Debug.Break();
        }

        Dbg.LogRelease(this, "APP: Restoring Gravity");
        Physics.gravity = gravityToRestore;
        setupRoutine    = null;
    }
コード例 #3
0
    void OnSceneLoaded()
    {
        if (setupRoutine != null)
        {
            Dbg.LogErrorRelease(this, "APP: Tried to start setup routine while in setup routine");
            return;
        }

        setupRoutine = StartCoroutine(
            OnSceneLoadedRoutine()
            );
    }
コード例 #4
0
    void OnValidate()
    {
        bool invalidPrefab =
            !Application.isPlaying &&
            prefab != null &&
            (!EditorUtility.IsPersistent(prefab) ||
             PrefabUtility.GetPrefabParent(PrefabUtility.FindRootGameObjectWithSameParentPrefab(gameObject)) == prefab);

        if (invalidPrefab)
        {
            Dbg.LogErrorRelease(this, "{0} had an invalid prefab", this);
            prefab = null;
        }
    }
コード例 #5
0
ファイル: EnumHelper.cs プロジェクト: EliGould/HordeMode
    static EnumHelper()
    {
        Type type = typeof(T);

        if (type.IsEnum)
        {
            values    = (T[])Enum.GetValues(type);
            count     = values.Length;
            names     = Enum.GetNames(type);
            intValues = new int[count];
            for (int i = 0; i < count; ++i)
            {
                intValues[i] = Convert.ToInt32(values[i]);
            }
        }
        else
        {
            Dbg.LogErrorRelease("Used EnumHelper<T> with a type that isn't a enum");
            count     = 0;
            values    = null;
            intValues = null;
            names     = null;
        }
    }
コード例 #6
0
        void DrawWithEditor(SerializedProperty property)
        {
            Editor editor = Editor.CreateEditor(property.objectReferenceValue);

            if (editor == null)
            {
                return;
            }

            Rect foldoutRect = GUILayoutUtility.GetLastRect();

            foldoutRect.width   = 20.0f;
            property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, "");

            if (property.isExpanded)
            {
                if (property.isArray)
                {
                    property.arraySize = EditorGUILayout.IntField("Size", property.arraySize);
                }

                try
                {
                    EditorGUILayoutHelper.Indent(() =>
                    {
                        editor.OnInspectorGUI();
                    });
                }
                catch (Exception exc)
                {
                    Dbg.LogExc(exc);
                    Dbg.LogErrorRelease("Exception thrown with InlineObjectAttriute.useEditor = true. Does the serialized object type have an Editor?");
                    throw exc;
                }
            }
        }
コード例 #7
0
    IEnumerator LoadSceneRoutine(string scene)
    {
        Dbg.LogRelease(this, "APP: Will load scene {0}", scene);

        OnSceneWillUnload();

        isLoading = true;

        BeginLoadingScope("Loading load scene");
        SceneManager.LoadScene(loadingSceneName);

        // The actual loading starts 'next frame'
        yield return(null);

        EndLoadingScope();

        Dbg.LogWarnReleaseIf(
            Game.callbackCounter != 0,
            this,
            "APP: Game had {0} callbacks still registered. These will be cleared, but should be properly taken care of.",
            Game.callbackCounter
            );

        Game.ClearCallbacks();

        BeginLoadingScope("Unloading unused assets");
        loadOperation = Resources.UnloadUnusedAssets();
        loadMessage   = "Unloading Unused Assets";
        yield return(loadOperation);

        loadOperation = null;
        EndLoadingScope();

        // Wait if something wants to fade in or such
        // before loading starts
        while (delaySceneLoad)
        {
            yield return(null);
        }

        loadMessage   = scene;
        loadOperation = SceneManager.LoadSceneAsync(scene);

        if (loadOperation == null)
        {
            loadSceneRoutine = null;
            loadOperation    = null;

            Dbg.LogErrorRelease(this, "APP: Failed to start loading {0}, was probably not added to settings", scene);
            yield break;
        }

        loadOperation.allowSceneActivation = false;

        BeginLoadingScope("Loading scene");
        // AsyncOp will never return isDone if
        // allowSceneActivation is false, so
        // wait until 0.9
        while (loadOperation.progress < 0.9f)
        {
            yield return(null);
        }
        EndLoadingScope();

        // Give other stuff a frame to delay
        // the scene
        yield return(null);

        while (delayActivatingScene)
        {
            yield return(null);
        }

        loadOperation.allowSceneActivation = true;

        // Now wait until isDone is true
        while (!loadOperation.isDone)
        {
            yield return(null);
        }

        // Let scene load method piggyback on this
        // coroutine but still reset variables,
        // a new scene load may be initiated from
        // OnSceneLoaded
        isLoading        = false;
        loadSceneRoutine = null;
        loadOperation    = null;

        OnSceneLoaded();
    }