コード例 #1
0
    public override void Init(CUIManager Context)
    {
        base.Init(Context);

        CToolkitUI ui = CGame.ToolkitUI;

        _base = ui.CreateElement(CGame.UIManager.mMenuLayer, "mainMenuBase");
        _base.AddComponent <Image>().color = new Color(0.2f, 0.2f, 0.2f, 1.0f);
        ui.SetRectFillParent(_base);

        logo = ui.CreateElement(_base, "logo");
        Image logoImage = logo.AddComponent <Image>();

        logoImage.sprite = CGame.PrimaryResources.Sprites[1];
        //logoImage.SetNativeSize();
        logoImage.preserveAspect = true;
        logoImage.color          = new Color(1.0f, 1.0f, 1.0f);
        //logo.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0);
        logo.GetComponent <RectTransform>().anchorMin        = new Vector2(0.5f, 0.0f);
        logo.GetComponent <RectTransform>().anchorMax        = new Vector2(0.5f, 1.0f);
        logo.GetComponent <RectTransform>().pivot            = new Vector2(0.5f, 0.5f);
        logo.GetComponent <RectTransform>().sizeDelta        = new Vector2(256, 256);
        logo.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 0);

        _splashBase = ui.CreateElement(CGame.UIManager.mMenuLayer, "splashBase");
        _splashBase.AddComponent <Image>().color = new Color(0.2f, 0.2f, 0.2f, 0.0f);
        ui.SetRectFillParent(_splashBase);

        CGame.UIManager.PlayMusic(0);
    }
コード例 #2
0
 public CTUITreeView(CToolkitUI ToolkitUI, GameObject TreeViewGOB)
 {
     mUI                 = ToolkitUI;
     mGob                = TreeViewGOB;
     mRootItem           = new CTUITreeViewItem(this, null);
     mRootItem.mExpanded = true;
 }
コード例 #3
0
    public CTooltip(CToolkitUI Toolkit, CGameUIStyle Style, GameObject Root)
    {
        _ui    = Toolkit;
        _style = Style;

        _tooltipOverGame = false;
        _tooltip         = _ui.CreateElement(Root, "tooltip");
        _ui.AddImage(_tooltip, _style.TooltipBackground);
        _ui.SetTransform(_tooltip, 0, 0, 256, 256);
        _ui.AddVerticalLayout(_tooltip, new RectOffset(3, 3, 3, 3), 3);
        _tooltip.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0);
        _tooltip.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);
        ContentSizeFitter fitter = _tooltip.AddComponent <ContentSizeFitter>();

        fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
        fitter.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

        float width = 150.0f;

        GameObject title = _ui.CreateTextElement(_tooltip, "Title", "title", CToolkitUI.ETextStyle.TS_HEADING);

        _ui.AddLayout(title, width, -1, -1, -1);

        GameObject details = _ui.CreateTextElement(_tooltip, "Sub-title", "subtitle", CToolkitUI.ETextStyle.TS_DEFAULT);

        _ui.AddLayout(details, width, -1, -1, -1);

        GameObject desc = _ui.CreateTextElement(_tooltip, "Description text that can be longer.", "description", CToolkitUI.ETextStyle.TS_HEADING);

        _ui.AddLayout(desc, width, -1, -1, -1);

        Hide(false);
    }
コード例 #4
0
    public void Init(CToolkitUI UI)
    {
        QualitySettings.vSyncCount = 0;

        mUI = UI;

        mPrimaryRT = RenderTexture.GetTemporary(Screen.width, Screen.height, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Default, 8);
        Camera.main.targetTexture = mPrimaryRT;

        CreateBaseUI();
        CreateWindow(new CAssetEditor());
        ShowWindow(_windows[0]);
    }
コード例 #5
0
    private void _ShowMainMenu()
    {
        // Create main menu stuff
        CToolkitUI ui = CGame.ToolkitUI;

        CJSONParser json       = new CJSONParser();
        CJSONValue  levelArray = json.Parse(CGame.DataDirectory + "campaign.txt");

        GameObject button;

        if (levelArray != null)
        {
            int levelCount = 0;

            for (int i = 0; i < levelArray.GetCount(); ++i)
            {
                CJSONValue level = levelArray[i];

                string levelName = level.GetString("name", "unknown");
                string assetName = level.GetString("asset", "unknown");
                bool   playable  = level.GetBool("playable");
                bool   visible   = level.GetBool("visible");

                if (visible)
                {
                    button = ui.CreateMenuButton(_base, levelName + " (" + assetName + ".pwa)", () =>
                    {
                        CGame.UIManager.PlaySound(CGame.PrimaryResources.AudioClips[15]);
                        _PlayLevel(assetName);
                    }, 1, playable);
                    ui.SetTransform(button, 50, -100 - (levelCount++ *30), 512, 50);
                }
            }
        }

        /*
         * button = CreateButton(_base, "Sample (cutscene)", null);
         * ui.SetTransform(button, 50, -150, 256, 50);
         */

        /*
         * button = CreateButton(_base, "Multiplayer", null);
         * ui.SetTransform(button, 50, -200, 256, 50);
         *
         * button = CreateButton(_base, "Options", null);
         * ui.SetTransform(button, 50, -250, 256, 50);
         */

        button = ui.CreateMenuButton(_base, "Quit", _Exit);
        ui.SetTransform(button, 50, -30, 256, 50);
    }
コード例 #6
0
    public CContextMenu(CToolkitUI Toolkit, CGameUIStyle Style, GameObject Root)
    {
        _ui    = Toolkit;
        _style = Style;

        _root = _ui.CreateElement(Root, "contextMenuRoot");
        _ui.AddImage(_root, new Color(0, 0, 0, 0.0f));
        _ui.SetRectFillParent(_root);
        _root.AddComponent <CUIContextMenuOverlay>();

        _contextMenu = _ui.CreateElement(_root, "contextMenu");
        _ui.AddImage(_contextMenu, _style.TooltipBackground);
        _ui.SetTransform(_contextMenu, 0, 0, 128, 256);
        _ui.AddVerticalLayout(_contextMenu, new RectOffset(3, 3, 3, 3), 3);
        _contextMenu.GetComponent <RectTransform>().anchorMax = new Vector2(0, 0);
        _contextMenu.GetComponent <RectTransform>().anchorMin = new Vector2(0, 0);

        ContentSizeFitter fitter = _contextMenu.AddComponent <ContentSizeFitter>();

        fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
        fitter.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

        Hide();
    }
コード例 #7
0
 public virtual void Init(CAssetToolkit Toolkit)
 {
     mToolkit = Toolkit;
     mUI      = Toolkit.mUI;
 }
コード例 #8
0
    protected override void _Update(CUserSession UserSession)
    {
        CToolkitUI ui = CGame.ToolkitUI;

        // TODO: Do this after we have moved the unit -__-
        Vector3 pivot = _Gob.transform.position;

        mBounds = new Bounds(pivot + new Vector3(0.0f, 0.5f, 0.0f), new Vector3(1.0f, 1.0f, 1.0f));

        if (_carryGOB != null)
        {
            if (!mCarryingPickup)
            {
                GameObject.Destroy(_carryGOB);
            }
            else
            {
                if (mWalking)
                {
                    _carryGOB.transform.localPosition = new Vector3(0.0f, 1.05f + Mathf.Sin(Time.time * 20.0f) * 0.05f, 0.3f);
                }
            }
        }
        else
        {
            if (mCarryingPickup)
            {
                _carryGOB = CGame.AssetManager.GetAsset <CModelAsset>("pickup").mVectorModel.CreateGameObject();
                _carryGOB.GetComponent <MeshRenderer>().material.SetColor("_FloorColor", new Color(150.0f / 255.0f, 150.0f / 255.0f, 150.0f / 255.0f, 1.0f));

                _carryGOB.transform.SetParent(_Gob.transform);
                _carryGOB.transform.localPosition = new Vector3(0.0f, 1.0f, 0.3f);
                _carryGOB.transform.localRotation = Quaternion.Euler(-10, 0, 0);
            }
        }

        // Icon Stack

        /*
         * {
         *      Vector3 screenPos = Camera.main.WorldToScreenPoint(_Gob.transform.position + new Vector3(0.0f, 1.6f, 0.0f));
         *      Vector2 bubbleUIPos = CGame.UIManager.ConvertScreenSpaceToUISpace(new Vector2(screenPos.x, screenPos.y));
         *      ((RectTransform)_iconStackGob.transform).anchoredPosition = bubbleUIPos;
         * }
         * if (_bubbleTime > 0.0f)
         * {
         *      _UIThought.SetActive(true);
         *      _UIThoughtText.text = _thoughtText;
         *
         *      float y = ((RectTransform)_UIThought.transform).anchoredPosition.y;
         *      // TODO: Safegaurd lerp.
         *      y = Mathf.Lerp(y, _iconStackBaselineTarget, 10.0f * Time.deltaTime);
         *      ((RectTransform)_UIThought.transform).anchoredPosition = new Vector2(0.0f, y);
         *      _bubbleTime -= Time.deltaTime;
         * }
         * else
         * {
         *      _UIThought.SetActive(false);
         * }
         *
         * if (_iconSelectorGob != null)
         * {
         *      _iconSelectorLerp -= Time.deltaTime * 7.0f;
         *
         *      if (_iconSelectorLerp < 0.0f)
         *              _iconSelectorLerp = 0.0f;
         *
         *      ((RectTransform)_iconSelectorGob.transform).anchoredPosition = new Vector2(0.0f, Mathf.Sin(Time.time * 10.0f) * 8.0f - 4.0f + 600.0f * CGame.UIResources.UnitIconDropCurve.Evaluate(1.0f - _iconSelectorLerp));
         * }
         */

        /*
         * if (!mDead)
         * {
         *      _HealthBar.SetActive(true);
         *      Vector3 screenPos = Camera.main.WorldToScreenPoint(GetVisualPos() + new Vector3(0.0f, 2.0f, 0.0f));
         *      ((RectTransform)_HealthBar.transform).anchoredPosition = new Vector2((int)screenPos.x, (int)screenPos.y);
         *      _HealthBarFill.transform.localScale = new Vector3(mStamina / mMaxStamina, 1.0f, 1.0f);
         * }
         * else
         * {
         *      _HealthBar.SetActive(false);
         * }
         */

        /*
         * if (mPathing)
         * {
         *      if (mSpeed >= 4.0f)
         *              _footStepAudioTimer += 3.0f * Time.deltaTime;
         *      else if (mSpeed >= 2.0f)
         *              _footStepAudioTimer += 2.2f * Time.deltaTime;
         *      else if (mSpeed > 0.0f)
         *              _footStepAudioTimer += 1.6f * Time.deltaTime;
         *
         *      if (_footStepAudioTimer > 1.0f)
         *      {
         *              _footStepAudioTimer = 0.0f;
         *              PlaySound(0, 6.0f);
         *      }
         *
         *      // Walking
         *
         *      //_Animator.SetFloat("Speed", mSpeed);
         * }
         * else
         * {
         *      _footStepAudioTimer = 0.0f;
         *      //_Animator.SetFloat("Speed", 0.0f);
         * }
         */

        //_Animator.SetBool("Sitting", mSitting);
        //_Animator.SetBool("Dead", mDead);

        /*
         * if (mFrustrated || mEating)
         *      _Animator.SetLayerWeight(1, 1.0f);
         * else
         *      _Animator.SetLayerWeight(1, 0.0f);
         *
         * _Animator.SetBool("Eating", mEating);
         *
         * if (mFrustrated != _oldFrustrated)
         * {
         *      _oldFrustrated = mFrustrated;
         *
         *      if (mFrustrated)
         *              _Animator.SetTrigger("FrustrateTrigger");
         * }
         * */

        //CDebug.DrawZRect(_unit.mBounds.center, 0.1f, 0.01f * _unit.mStamina, Color.red);

        // Interpolate to simulated position
        Vector3 targetPos  = new Vector3(mPosition.x, 0.0f, mPosition.y);
        Vector3 currentPos = _Gob.transform.position;
        Vector3 dir        = targetPos - currentPos;
        float   distance   = dir.magnitude;

        // Teleport to position if we are too far away
        if (distance >= 3.0f)
        {
            currentPos = targetPos;

            // Reset dynamics on teleport
            Transform neck    = _Gob.transform.FindChild("unit_test/Hips/Spine/Chest/Neck");
            Vector3   forward = _Gob.transform.TransformDirection(Vector3.forward);

            _joints[0] = new SDynamicsJoint(neck.position + forward * 0.1f, true);
            _joints[1] = new SDynamicsJoint(_joints[0].mPosition + Vector3.down * 0.13f, false);
            _joints[2] = new SDynamicsJoint(_joints[1].mPosition + Vector3.down * 0.13f, false);
            _joints[3] = new SDynamicsJoint(_joints[2].mPosition + Vector3.down * 0.13f, false);
        }
        else
        {
            currentPos = Vector3.Lerp(currentPos, targetPos, Mathf.Clamp(Time.deltaTime * 10.0f, 0.0f, 1.0f));
        }

        _prevRotation = Quaternion.Slerp(_prevRotation, mRotation, 5.0f * Time.deltaTime);
        //_prevRotation = Quaternion.RotateTowards(_prevRotation, mRotation, 300.0f * Time.deltaTime);
        _Gob.transform.position = currentPos;
        _Gob.transform.rotation = _prevRotation;

        _Animator.speed = 1.0f;

        if (_Animator.isInitialized)
        {
            if (mDead)
            {
                _PlayAnimation("dying_1", -1);
            }
            else if (mActionAnim != "")
            {
                _Animator.speed = mAnimSpeed;
                _PlayAnimation(mActionAnim, -1, false);
            }
            else if (mWalking)
            {
                if (mCarryingPickup)
                {
                    _PlayAnimation("walking_with_item", -1);
                }
                else
                {
                    if (mSpeed > 2.0f)
                    {
                        _PlayAnimation("running_no_item", -1);
                        _Animator.SetFloat("walkSpeed", mSpeed * 0.6f);
                    }
                    else
                    {
                        if (mStamina < 50.0f)
                        {
                            _Animator.SetFloat("walkSpeed", mSpeed * 1.0f);
                            _PlayAnimation("walking_exhausted", -1);
                        }
                        else
                        {
                            _Animator.SetFloat("walkSpeed", mSpeed * 0.5f + 0.5f);
                            _PlayAnimation("walking_no_item", -1);
                        }
                    }
                }
            }
            else if (mAttacking)
            {
                _PlayAnimation("combat_bashing", -1);
            }
            else
            {
                float r = UnityEngine.Random.value;

                if (r > 0.8f)
                {
                    _PlayAnimation("idle_standing_action_1", 1.0f);
                }
                else if (r > 0.6f)
                {
                    _PlayAnimation("idle_standing_action_2", 1.0f);
                }
                else
                {
                    _PlayAnimation("idle_standing_general", 5.0f);
                }
            }
        }

        // Sound
        if (SoundID > SoundLastPlayedID)
        {
            _AudioSource.pitch = CGame.UniversalRandom.GetNextFloat() * 0.5f + 0.75f;
            _AudioSource.PlayOneShot(CGame.Resources.GetAudioClip(SoundType), SoundVolume);
            SoundLastPlayedID = SoundID;
        }

        if (mAssignedDeskID == -1)
        {
            if (_texState != 0)
            {
                _texState = 0;
                _Gob.transform.GetChild(0).GetChild(0).GetComponent <SkinnedMeshRenderer>().material.SetTexture("_MainTex", CGame.PrimaryResources.UnitTexTie);
            }
        }
        else
        {
            if (_texState == 0)
            {
                _texState = 1;
                //_Gob.transform.GetChild(0).GetChild(0).GetComponent<SkinnedMeshRenderer>().material.SetTexture("_MainTex", CGame.PrimaryResources.UnitTexTieArmband);
            }
        }

        // TODO: Hide briefcase when sitting/using?

        /*
         * if (_briefcaseGOB != null)
         * {
         *      if (mAssignedDeskID == -1)
         *      {
         *              _briefcaseGOB.SetActive(true);
         *      }
         *      else
         *      {
         *              _briefcaseGOB.SetActive(false);
         *      }
         * }
         */

        if (mOwner == UserSession.mPlayerIndex)
        {
            if (_indicatorGob == null)
            {
                _indicatorGob = ui.CreateElement(CGame.UIManager.overlayLayer, "indicator");
                ui.SetAnchors(_indicatorGob, Vector2.zero, Vector2.zero, new Vector2(0.5f, 0.0f));
                ui.SetTransform(_indicatorGob, 50, -200, 56, 65);
                Image indImg = _indicatorGob.AddComponent <Image>();
                indImg.color  = new Color(0.2f, 0.2f, 0.2f, 0.5f);
                indImg.sprite = ui.IndicatorBkg;

                GameObject indIcon = ui.CreateElement(_indicatorGob, "icon");
                ui.SetAnchors(indIcon, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f));
                ui.SetTransform(indIcon, 0, 3, 56, 56);
                indImg       = indIcon.AddComponent <Image>();
                indImg.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);

                _indicatorGob.transform.localScale = new Vector3(0.75f, 0.75f, 0.75f);
                //_indicatorGob.transform.localScale = new Vector3(0.75f, 0.75f, 0.75f);
            }

            mThoughtTime += Time.deltaTime;

            if (mLastThoughtState != mThoughtState)
            {
                mThoughtTime = 0.0f;
                Image indImg = _indicatorGob.transform.GetChild(0).GetComponent <Image>();
                mLastThoughtState = mThoughtState;

                indImg.sprite = ui.IndicatorNoDesk;
            }

            if (mThoughtTime < 2.0f)
            {
                mThoughtAlpha += Time.deltaTime * 5.0f;
            }
            else
            {
                mThoughtAlpha -= Time.deltaTime * 5.0f;
            }

            mThoughtAlpha = Mathf.Clamp01(mThoughtAlpha);

            if (mThoughtAlpha > 0.0f)
            {
                _indicatorGob.SetActive(true);
                Vector3 screenPos = Camera.main.WorldToScreenPoint(_Gob.transform.position + new Vector3(0.0f, 1.8f, 0.0f));
                ((RectTransform)_indicatorGob.transform).anchoredPosition = new Vector2((int)screenPos.x, (int)screenPos.y);
                _indicatorGob.GetComponent <Image>().color = new Color(0.2f, 0.2f, 0.2f, 0.5f * mThoughtAlpha);
                _indicatorGob.transform.GetChild(0).GetComponent <Image>().color = new Color(1.0f, 1.0f, 1.0f, 1.0f * mThoughtAlpha);
            }
            else
            {
                _indicatorGob.SetActive(false);
            }
        }

        if (mSpeech != "")
        {
            if (mSpeechBubble == null)
            {
                mSpeechBubble = ui.CreateElement(CGame.UIManager.overlayLayer, "speechBubble");
                ui.SetAnchors(mSpeechBubble, Vector2.zero, Vector2.zero, new Vector2(0.5f, 0.0f));
                ui.SetTransform(mSpeechBubble, 50, -200, 100, 20);
                ui.AddImage(mSpeechBubble, new Color(1.0f, 1.0f, 1.0f, 1.0f));
                ui.AddHorizontalLayout(mSpeechBubble, new RectOffset(8, 8, 8, 8));
                ContentSizeFitter fitter = mSpeechBubble.AddComponent <ContentSizeFitter>();
                fitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
                fitter.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;

                GameObject text = ui.CreateElement(mSpeechBubble, "text");
                mSpeechBubbleText       = text.AddComponent <Text>();
                mSpeechBubbleText.font  = CGame.GameUIStyle.FontB;
                mSpeechBubbleText.color = CGame.GameUIStyle.ThemeColorC;
                mSpeechBubbleText.text  = "";

                mSpeechTimer = 0;
            }

            Vector3 screenPos = Camera.main.WorldToScreenPoint(_Gob.transform.position + new Vector3(0.0f, 2.0f, 0.0f));
            ((RectTransform)mSpeechBubble.transform).anchoredPosition = new Vector2((int)screenPos.x, (int)screenPos.y);

            while (mSpeechTimer >= 0.03f)
            {
                mSpeechTimer -= 0.03f;

                if (mSpeechBubbleText.text != mSpeech)
                {
                    if (mSpeech.Length < mSpeechBubbleText.text.Length)
                    {
                        mSpeechBubbleText.text = mSpeech[0].ToString();
                    }
                    else
                    {
                        bool match = true;
                        for (int i = 0; i < mSpeechBubbleText.text.Length; ++i)
                        {
                            if (mSpeechBubbleText.text[i] != mSpeech[i])
                            {
                                mSpeechBubbleText.text = mSpeech[0].ToString();
                                match = false;
                                break;
                            }
                        }

                        if (match)
                        {
                            mSpeechBubbleText.text += mSpeech[mSpeechBubbleText.text.Length];
                        }
                    }
                }
            }

            mSpeechTimer += Time.deltaTime;
        }
        else
        {
            GameObject.Destroy(mSpeechBubble);
            mSpeechBubble     = null;
            mSpeechBubbleText = null;
        }

        if (mOwner == UserSession.mPlayerIndex)
        {
            Vector3 pos = _Gob.transform.position;
            CPunchOut.UpdateMesh(_punchOutMesh, _worldView, pos.ToWorldVec2(), 8.0f);
            _punchOut.transform.position = new Vector3(pos.x, 0.0f, pos.z);
            _punchOut.transform.rotation = Quaternion.identity;

            if (mUIEmployeeEntry != null)
            {
                //mUIEmployeeEntry.mStaminaBar.localScale = new Vector3(mStamina / mStats.mMaxStamina, 1, 1);
            }
        }

        /*
         * if (mID == 6)
         * {
         *      CGame.CameraManager.SetTargetPosition(mPosition.ToWorldVec3());
         * }
         */

        _Gob.transform.GetChild(0).GetChild(0).GetComponent <SkinnedMeshRenderer>().material.SetFloat("_Stam", mStamina / 100.0f);
    }
コード例 #9
0
ファイル: CGame.cs プロジェクト: VectorShiftStudios/Paperwork
    /// <summary>
    /// Game startup.
    /// </summary>
    public CGame(CUnityInterface Interface, string CommandLineArgs)
    {
        _cmdArgs = CommandLineArgs.Split(' ');
        string[] parms;

#if !UNITY_EDITOR
        DataDirectory           = Application.dataPath + "/Data/";
        PersistentDataDirectory = Application.persistentDataPath + "/";
#else
        DataDirectory           = "Data/";
        PersistentDataDirectory = "SaveData/";
#endif

        Config = new CConfig(PersistentDataDirectory + "config.txt");
        Config.Load();

#if !UNITY_EDITOR
        DataDirectory           = Application.dataPath + "/Data/";
        PersistentDataDirectory = Application.persistentDataPath + "/";

        if (_CheckArg("dev", out parms))
        {
            Screen.SetResolution(1280, 720, false);
        }
        else
        {
            string resType = Config.GetString("ResolutionType");

            if (resType == "default")
            {
                Resolution r = Screen.resolutions[Screen.resolutions.Length - 1];
                Screen.SetResolution(r.width, r.height, true);
            }
            else if (resType == "fullscreen" || resType == "windowed")
            {
                Resolution r    = Screen.resolutions[Screen.resolutions.Length - 1];
                int        resX = (int)Config.GetFloat("ResolutionWidth");
                int        resY = (int)Config.GetFloat("ResolutionHeight");

                Screen.SetResolution(resX, resY, (resType == "fullscreen"));
            }
        }
#endif

        CUtility.MakeDirectory(PersistentDataDirectory + SAVES_DIRECTORY);
        CUtility.MakeDirectory(PersistentDataDirectory + REPLAYS_DIRECTORY);

        PrimaryResources = Interface.GetComponent <CPrimaryResources>();
        WorldResources   = Interface.GetComponent <CWorldResources>();
        UIResources      = Interface.GetComponent <CUIResources>();
        ToolkitUI        = Interface.GetComponent <CToolkitUI>();
        GameUIStyle      = Interface.GetComponent <CGameUIStyle>();

        Console = new CConsole();

        Debug.Log("Save game directory: " + PersistentDataDirectory);
        Debug.Log("Data directory: " + DataDirectory);

        VarShowGrid        = Console.CreateVar("show_grid", false);
        VarShowVisLines    = Console.CreateVar("show_los", false);
        VarShowDDATest     = Console.CreateVar("show_ddatest", false);
        VarShowArcTest     = Console.CreateVar("show_arctest", false);
        VarShowBounds      = Console.CreateVar("show_bounds", false);
        VarShowDebugStats  = Console.CreateVar("show_debugstats", false);
        VarShowMobility    = Console.CreateVar("show_mobility", 0, 0, CWorld.MAX_PLAYERS);
        VarShowSolidity    = Console.CreateVar("show_solidity", 0, 0, CWorld.MAX_PLAYERS + 1);
        VarShowProfiler    = Console.CreateVar("show_profiler", false);
        VarNoFow           = Console.CreateVar("no_fow", false);
        VarPlaceItemDirect = Console.CreateVar("place_item_direct", false);
        VarShowComfort     = Console.CreateVar("show_comfort", false);
        VarShowEfficiency  = Console.CreateVar("show_efficiency", false);

        VarShowPathing   = Console.CreateVar("pathing", false);
        VarShowFlowField = Console.CreateVar("show_flowfield", false);
        VarShowNavMesh   = Console.CreateVar("show_navmesh", false);
        VarShowNavRect   = Console.CreateVar("show_navrect", 0, 0, CWorld.MAX_PLAYERS);
        VarShowProxies   = Console.CreateVar("show_proxies", 0, 0, CWorld.MAX_PLAYERS);

        VarFreePurchases = Console.CreateVar("freebuy", true);
        Console.CreateCommand("gameui", (Params) => { UIManager.ToggleUIActive(); });
        Console.CreateCommand("quit", (Params) => { ExitApplication(); });
        Console.CreateCommand("exit", (Params) => { ExitApplication(); });
        Console.CreateCommand("set_owed", (Params) => { if (_gameSession == null)
                                                        {
                                                            return;
                                                        }
                                                        _gameSession.SetOwed(1000); });
        Console.CreateCommand("set_stamina", (Params) => { if (_gameSession == null)
                                                           {
                                                               return;
                                                           }
                                                           _gameSession.SetStamina(10.0f); });
        Console.CreateCommand("set_hunger", (Params) => { if (_gameSession == null)
                                                          {
                                                              return;
                                                          }
                                                          _gameSession.SetHunger(80); });
        Console.CreateCommand("rebuild_icons", (Params) => { IconBuilder.RebuildItemIcons(true); });

        Game  = this;
        Steam = new CSteam();
        PrimaryThreadProfiler = new CProfiler();
        SimThreadProfiler     = new CProfiler();
        DebugLevels           = new CDebugLevels();
        UniversalRandom       = new CRandomStream();
        AssetManager          = new CAssetManager();
        Net           = new CNet();
        Resources     = new CResources();
        CameraManager = new CCameraManager();
        UIManager     = new CUIManager(ToolkitUI, GameUIStyle);
        CDebug.StaticInit();
        AssetManager.Init();
        ProfilerManager = new CProfilerManager();
        ProfilerManager.Init();
        IconBuilder = new CIconBuilder();
        IconBuilder.Init();
        _inputState = new CInputState();

        Console.Hide();
        Analytics.SetUserId(Steam.mSteamID.ToString());

        // TODO: Backquote is not ~, investigate.
        // TOOD: Allow the same command to have multiple keys associated with it.
        _inputState.RegisterCommand("console", Config.GetString("KeyConsole"), true);

        _inputState.RegisterCommand("escape", Config.GetString("KeyEscape"));

        _inputState.RegisterCommand("focusOnSpawn", Config.GetString("KeyFocusOnSpawn"));

        _inputState.RegisterCommand("camForward", Config.GetString("KeyCamForward"));
        _inputState.RegisterCommand("camLeft", Config.GetString("KeyCamLeft"));
        _inputState.RegisterCommand("camBackward", Config.GetString("KeyCamBackward"));
        _inputState.RegisterCommand("camRight", Config.GetString("KeyCamRight"));
        _inputState.RegisterCommand("camRotateLeft", KeyCode.Delete);
        _inputState.RegisterCommand("camRotateRight", KeyCode.PageDown);

        _inputState.RegisterCommand("itemPlaceRotate", Config.GetString("KeyPlaceRotate"));
        _inputState.RegisterCommand("itemPlaceRepeat", Config.GetString("KeyPlaceRepeat"));

        _inputState.RegisterCommand("action1", Config.GetString("KeyAction1"));
        _inputState.RegisterCommand("action2", Config.GetString("KeyAction2"));
        _inputState.RegisterCommand("action3", Config.GetString("KeyAction3"));
        _inputState.RegisterCommand("action4", Config.GetString("KeyAction4"));

        _inputState.RegisterCommand("openOptions", Config.GetString("KeyOptionsMenu"));

        _inputState.RegisterCommand("reload", KeyCode.F5);
        _inputState.RegisterCommand("space", KeyCode.Space);

        _inputState.RegisterCommand("editorDelete", Config.GetString("KeyEditorDelete"));
        _inputState.RegisterCommand("editorDuplicate", Config.GetString("KeyEditorDuplicate"));
        _inputState.RegisterCommand("editorUndo", Config.GetString("KeyEditorUndo"));
        _inputState.RegisterCommand("editorRedo", Config.GetString("KeyEditorRedo"));
        _inputState.RegisterCommand("editorSave", Config.GetString("KeyEditorSave"));

        // Apply default settings
        //Application.targetFrameRate = 60;
        //QualitySettings.antiAliasing

        // Volume range: 0.0 - -80.0
        // TODO: Volume in DB is exponential, making 0 to 1 range for config ineffective.
        UIResources.MasterMixer.SetFloat("MasterVolume", CMath.MapRangeClamp(Config.GetFloat("MasterVolume"), 0, 1, -80, -12));
        UIResources.MasterMixer.SetFloat("MusicVolume", CMath.MapRangeClamp(Config.GetFloat("MusicVolume"), 0, 1, -80, 0));
        UIResources.MasterMixer.SetFloat("SoundsVolume", CMath.MapRangeClamp(Config.GetFloat("SoundsVolume"), 0, 1, -80, 0));
        UIResources.MasterMixer.SetFloat("UISoundsVolume", CMath.MapRangeClamp(Config.GetFloat("UISoundsVolume"), 0, 1, -80, 0));

        // NOTE: BE SUPER CAREFUL WITH THIS
        // You can corrupt ALL the item assets if not careful.
        // Saves asset to disk, but asset currently in memory won't reflect new version.
        //_resaveAllItemAssetsToLastestVersion();

        // TODO: This bootstraps all model assets on startup.
        // If the model asset is first loaded by the sim thread, then it will crash as it tries to generate the meshes.
        // Should probably only generate meshes when they are pulled in by the main thread.
        _testItemAssetVersion();

        if (_CheckArg("toolkit", out parms))
        {
            StartAssetToolkit();
        }
        else if (_CheckArg("map", out parms))
        {
            if (parms != null && parms.Length > 0)
            {
                CGameSession.CStartParams startParams = new CGameSession.CStartParams();
                startParams.mPlayType        = CGameSession.EPlayType.SINGLE;
                startParams.mUserPlayerIndex = 0;                 // Will be set by the level when loaded.
                startParams.mLevelName       = parms[0];
                StartGameSession(startParams);
            }
        }
        else
        {
            UIManager.AddInterface(new CMainMenuUI());
        }
    }
コード例 #10
0
    public CUIManager(CToolkitUI Toolkit, CGameUIStyle Style)
    {
        _ui    = Toolkit;
        _style = Style;
        _uiRes = CGame.UIResources;

        mPoseRT = new RenderTexture(512, 512, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
        mPoseRT.antiAliasing = 8;

        gameUI = _ui.CreateElement(_ui.Canvas, "gameUI");
        _ui.SetRectFillParent(gameUI);
        gameUI.transform.SetAsFirstSibling();

        underlayLayer = _ui.CreateElement(gameUI, "underlayLayer");
        _ui.SetRectFillParent(underlayLayer);

        CanvasGroup cgroup = underlayLayer.AddComponent <CanvasGroup>();

        cgroup.blocksRaycasts = false;

        primaryLayer             = _ui.CreateElement(gameUI, "primaryLayer");
        mPrimaryLayerGroup       = primaryLayer.AddComponent <CanvasGroup>();
        mPrimaryLayerGroup.alpha = 1.0f;
        _ui.SetRectFillParent(primaryLayer);

        overlayLayer = _ui.CreateElement(gameUI, "overlayLayer");
        _ui.SetRectFillParent(overlayLayer);

        cgroup = overlayLayer.AddComponent <CanvasGroup>();
        cgroup.blocksRaycasts = false;

        cutsceneLayer = _ui.CreateElement(gameUI, "cutsceneLayer");
        _ui.SetRectFillParent(cutsceneLayer);
        GameObject letterBox = _ui.CreateElement(cutsceneLayer);

        _ui.SetAnchors(letterBox, new Vector2(0, 1), new Vector2(1, 1), new Vector2(0, 1));
        _ui.AddImage(letterBox, _style.ThemeColorC);
        _ui.SetTransform(letterBox, 0, 0, 0, 54);

        letterBox = _ui.CreateElement(cutsceneLayer);
        _ui.SetAnchors(letterBox, new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 0));
        _ui.AddImage(letterBox, _style.ThemeColorC);
        _ui.SetTransform(letterBox, 0, 0, 0, 54);

        mCutsceneLayerGroup                = cutsceneLayer.AddComponent <CanvasGroup>();
        mCutsceneLayerGroup.alpha          = 0.0f;
        mCutsceneLayerGroup.blocksRaycasts = false;

        /*
         * fadeOverLayer = _ui.CreateElement(gameUI, "fadeOverLayer");
         * _ui.SetRectFillParent(fadeOverLayer);
         * _ui.AddImage(fadeOverLayer, Color.black);
         */

        contextMenuLayer = _ui.CreateElement(gameUI, "contextMenuLayer");
        _ui.SetRectFillParent(contextMenuLayer);

        mMenuLayer = _ui.CreateElement(gameUI, "menuLayer");
        _ui.SetRectFillParent(mMenuLayer);

        GameObject productText = _ui.CreateTextElement(overlayLayer, CGame.PRODUCT_NAME + " (" + CGame.VERSION_MAJOR + "." + CGame.VERSION_MINOR + ") " + CGame.VERSION_NAME, "productText", CToolkitUI.ETextStyle.TS_HEADING);

        _ui.SetAnchors(productText, new Vector2(0, 1), new Vector2(1, 1), new Vector2(0, 1));
        _ui.SetTransform(productText, 5, 0, -10, 20);
        productText.GetComponent <Text>().alignment = TextAnchor.MiddleRight;

        mContextMenu = new CContextMenu(Toolkit, Style, contextMenuLayer);
        mTooltip     = new CTooltip(Toolkit, Style, overlayLayer);

        SetupForGameSession();
    }