예제 #1
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);
    }
예제 #2
0
    protected override void _New(CUserSession UserSession)
    {
        _Gob      = mAsset.CreateVisuals((EViewDirection)mRotation);
        _Gob.name = mAsset.mName;
        _Gob.transform.SetParent(UserSession.mPrimaryScene.transform);

        if (mBlueprint)
        {
            CUtility.SetLayerRecursively(_Gob.transform, 9);
            _currentSurfaceColor = Color.white;
        }
        else
        {
            if (mAsset.mItemType == EItemType.DESK)
            {
                _briedcaseGOB = GameObject.CreatePrimitive(PrimitiveType.Cube);
                _briedcaseGOB.GetComponent <MeshRenderer>().material = CGame.PrimaryResources.FlatMat;
                _briedcaseGOB.transform.SetParent(_Gob.transform);
                _briedcaseGOB.transform.localScale    = new Vector3(0.15f, 0.3f, 0.45f);
                _briedcaseGOB.transform.localPosition = new Vector3(0.626f, 0.69f, 1.473f);
                _briedcaseGOB.transform.rotation      = Quaternion.Euler(0.0f, -10.0f, 270.0f);

                _briedcaseGOB.SetActive(false);
            }
            else if (mAsset.mItemType == EItemType.SAFE)
            {
                /*
                 * _textGob = new GameObject("sceneText");
                 * _textGob.transform.SetParent(_Gob.transform);
                 *
                 * _textMesh = _textGob.AddComponent<TextMesh>();
                 * _textMesh.text = mValue.ToString();
                 * _textMesh.characterSize = 0.09f;
                 * _textMesh.fontSize = 32;
                 * _textMesh.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                 * _textMesh.anchor = TextAnchor.MiddleCenter;
                 * //text.font = CGame.ToolkitUI.SceneTextFont;
                 *
                 * _textGob.transform.localPosition = new Vector3(0.5f, 0.0f, 0.0f);
                 * _textGob.transform.rotation = Quaternion.Euler(90, 0, 0);
                 */
            }
            else if (mAsset.mItemType == EItemType.START)
            {
                if (mOwnerID == UserSession.mPlayerIndex)
                {
                    _punchOut = CPunchOut.Create(out _punchOutMesh);
                    _punchOut.transform.SetParent(_Gob.transform);
                }
            }
            else if (mAsset.mItemType == EItemType.DOOR)
            {
                _briedcaseGOB = (GameObject)GameObject.Instantiate(CGame.WorldResources.PadlockPrefab, new Vector3(0.5f, 2.25f, 1.0f), Quaternion.identity);
                _briedcaseGOB.transform.SetParent(_Gob.transform);
            }

            _audioSource = _Gob.AddComponent <AudioSource>();
            _audioSource.outputAudioMixerGroup = CGame.UIResources.SoundsMixer;
            _audioSource.spatialBlend          = 1.0f;
        }
    }
예제 #3
0
    protected override void _New(CUserSession UserSession)
    {
        /*
         * _iconStackGob = new GameObject("iconStack", typeof(RectTransform));
         * _iconStackGob.transform.SetParent(CGame.UIResources.UnitUIPanel.transform);
         * _iconStackGob.transform.localScale = Vector3.one;
         * _iconStackGob.GetComponent<RectTransform>().anchorMin = new Vector2(0.0f, 0.0f);
         * _iconStackGob.GetComponent<RectTransform>().anchorMax = new Vector2(0.0f, 0.0f);
         * _iconStackGob.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.0f);
         *
         * _UIThought = GameObject.Instantiate(CGame.UIResources.UnitThought) as GameObject;
         * _UIThought.transform.SetParent(_iconStackGob.transform);
         * _UIThought.transform.localScale = Vector3.one;
         * _UIThought.GetComponent<RectTransform>().anchoredPosition = new Vector2(0.0f, 0.0f);
         * _UIThoughtIcon = _UIThought.transform.GetChild(0).GetComponent<Image>();
         * _UIThoughtText = _UIThought.transform.GetChild(1).GetComponent<Text>();
         * _UIThoughtIcon.enabled = true;
         * _UIThought.SetActive(false);
         */

        _texState = 0;
        Color playerColor = _worldView.mPlayerViews[mOwner].mColor;

        if (mIntern)
        {
            //_Gob = GameObject.Instantiate(CGame.PrimaryResources.Prefabs[6]) as GameObject;
            _Gob = GameObject.Instantiate(CGame.PrimaryResources.Prefabs[7]) as GameObject;

            // Tie Colour
            _Gob.transform.GetChild(0).GetChild(0).GetComponent <SkinnedMeshRenderer>().material.SetColor("_PlayerColor", playerColor);
            _Gob.transform.GetChild(0).GetChild(0).GetComponent <SkinnedMeshRenderer>().material.SetTexture("_MainTex", CGame.PrimaryResources.UnitTexTieSling);

            _briefcaseGOB = new GameObject();
            Transform hand = _Gob.transform.FindChild("unit_test/Hips/");
            _briefcaseGOB.transform.SetParent(hand);
            _briefcaseGOB.transform.localPosition = new Vector3(0.02f, 0.02f, -0.065f);
            _briefcaseGOB.transform.localScale    = Vector3.one;

            GameObject briefcase = GameObject.CreatePrimitive(PrimitiveType.Cube);
            briefcase.transform.SetParent(_briefcaseGOB.transform);
            briefcase.GetComponent <MeshRenderer>().material = CGame.PrimaryResources.FlatMat;
            briefcase.GetComponent <MeshRenderer>().material.SetColor("_Color", playerColor);
            briefcase.transform.localScale    = new Vector3(0.05f * 0.7f, 0.1f * 0.7f, 0.15f * 0.7f);
            briefcase.transform.localPosition = new Vector3(0.0f, -0.035f, 0.0f);
            briefcase.transform.localRotation = Quaternion.Euler(0, 0, 0);

            _bagJoints    = new SDynamicsJoint[2];
            _bagJoints[0] = new SDynamicsJoint(hand.position, true);
            _bagJoints[1] = new SDynamicsJoint(hand.position + Vector3.down * 0.1f, false);
        }
        else
        {
            _Gob = GameObject.Instantiate(CGame.PrimaryResources.Prefabs[7]) as GameObject;

            // Tie Colour
            _Gob.transform.GetChild(0).GetChild(0).GetComponent <SkinnedMeshRenderer>().material.SetColor("_PlayerColor", playerColor);
            _Gob.transform.GetChild(0).GetChild(0).GetComponent <SkinnedMeshRenderer>().material.SetTexture("_MainTex", CGame.PrimaryResources.UnitTexTie);

            _briefcaseGOB = new GameObject();
            Transform hand = _Gob.transform.FindChild("unit_test/Hips/Spine/Chest/R_Clavicle1/R_Up_Arm 1/R_Elbow_Top 1");
            _briefcaseGOB.transform.SetParent(hand);
            _briefcaseGOB.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
            _briefcaseGOB.transform.localScale    = Vector3.one;

            GameObject briefcase = GameObject.CreatePrimitive(PrimitiveType.Cube);
            briefcase.GetComponent <MeshRenderer>().material = CGame.PrimaryResources.FlatMat;
            briefcase.GetComponent <MeshRenderer>().material.SetColor("_Color", playerColor);
            briefcase.transform.SetParent(_briefcaseGOB.transform);
            briefcase.transform.localScale    = new Vector3(0.05f, 0.1f, 0.15f);
            briefcase.transform.localPosition = new Vector3(0.0f, -0.05f, 0.0f);

            _bagJoints    = new SDynamicsJoint[2];
            _bagJoints[0] = new SDynamicsJoint(hand.position, true);
            _bagJoints[1] = new SDynamicsJoint(hand.position + Vector3.down * 0.1f, false);
        }

        _Gob.name = "Unit " + mID;
        _Gob.transform.SetParent(UserSession.mPrimaryScene.transform);

        _AudioSource = _Gob.GetComponent <AudioSource>();
        _Animator    = _Gob.GetComponentInChildren <Animator>();
        //_Material = _Gob.GetComponentInChildren<SkinnedMeshRenderer>().material;

        _prevRotation = mRotation;

        // Punch Out
        if (mOwner == UserSession.mPlayerIndex)
        {
            _punchOut = CPunchOut.Create(out _punchOutMesh);
            _punchOut.transform.SetParent(_Gob.transform);
            _punchOut.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
        }

        if (UserSession.mPlayerIndex == mOwner)
        {
            UserSession.OnEmployeeAdded(this);
        }

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

        _joints    = new SDynamicsJoint[4];
        _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);

        _tieGob = new GameObject("tie");
        _tieGob.transform.SetParent(UserSession.mPrimaryScene.transform);
        _tieGob.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
        MeshRenderer meshRenderer = _tieGob.AddComponent <MeshRenderer>();
        MeshFilter   meshFilter   = _tieGob.AddComponent <MeshFilter>();

        _tieMesh = new Mesh();
        _tieMesh.MarkDynamic();
        meshFilter.mesh       = _tieMesh;
        meshRenderer.material = CGame.PrimaryResources.TieMat;
        meshRenderer.material.SetColor("_Color", playerColor);
    }
예제 #4
0
    protected override void _Update(CUserSession UserSession)
    {
        _targetSurfaceColor = mSurfaceColor;
        float colorLerp = 2.0f * Time.deltaTime;

        colorLerp            = Mathf.Clamp(colorLerp, 0.0f, 1.0f);
        _currentSurfaceColor = Color.Lerp(_currentSurfaceColor, _targetSurfaceColor, colorLerp);

        SetItemSurfaceColour(mAsset.mItemType, _Gob, _currentSurfaceColor);

        Vector2 pivot = CItem.PivotRelativeToTile[mRotation];

        _Gob.transform.position = new Vector3(mPosition.x, 0.0f, mPosition.y) + new Vector3(pivot.x, 0.0f, pivot.y);
        _Gob.transform.rotation = CItem.RotationTable[mRotation];

        if (mBlueprint)
        {
            return;
        }

        if (mAsset.mItemType == EItemType.DOOR)
        {
            if (mDoorAngle > _doorAngle)
            {
                if (_doorAngle == 0.0f)
                {
                    _audioSource.clip = CGame.PrimaryResources.AudioClips[7];
                    _audioSource.Play();
                    //_audioSource.PlayOneShot(CGame.PrimaryResources.AudioClips[7]);
                    //AudioSource.PlayClipAtPoint(CGame.PrimaryResources.AudioClips[7], mPosition.ToWorldVec3(), 1.0f);
                }

                _doorAngle += CItemDoor.DOORSPEED * Time.deltaTime;
            }
            else if (mDoorAngle < _doorAngle)
            {
                if (_doorAngle == 1.0f)
                {
                    _audioSource.clip = CGame.PrimaryResources.AudioClips[8];
                    _audioSource.Play();
                    //_audioSource.PlayOneShot(CGame.PrimaryResources.AudioClips[8]);
                    //AudioSource.PlayClipAtPoint(CGame.PrimaryResources.AudioClips[8], mPosition.ToWorldVec3(), 1.0f);
                }

                _doorAngle -= CItemDoor.DOORSPEED * Time.deltaTime;
            }

            _doorAngle = Mathf.Clamp(_doorAngle, 0.0f, 1.0f);

            GameObject door = _Gob.transform.GetChild(0).gameObject;

            door.transform.rotation = Quaternion.Euler(0.0f, _doorAngle * 90.0f, 0.0f) * CItem.RotationTable[mRotation];

            if (mLocked)
            {
                _briedcaseGOB.SetActive(true);
                _briedcaseGOB.transform.Rotate(Vector3.up, 180.0f * Time.deltaTime);
            }
            else
            {
                _briedcaseGOB.SetActive(false);
            }
        }
        else if (mAsset.mItemType == EItemType.DESK)
        {
            if (mAssignedUnitID != -1)
            {
                /*
                 * Color playerColor = _worldView.mPlayerViews[_playerIndex].mColor;
                 * _briedcaseGOB.GetComponent<MeshRenderer>().material.SetColor("_Color", playerColor);
                 * _briedcaseGOB.SetActive(true);
                 */
            }
            else
            {
                //_briedcaseGOB.SetActive(false);
            }

            if (mLastPaperStackUpdateTick != mPaperStackUpdateTick)
            {
                RefreshContractVisuals();
                mLastPaperStackUpdateTick = mPaperStackUpdateTick;
            }
        }
        else if (mAsset.mItemType == EItemType.START)
        {
            if (_doorTarget != mDoorAngle)
            {
                if (mDoorAngle == 1.0f)
                {
                    //_audioSource.PlayOneShot(CGame.PrimaryResources.AudioClips[9]);
                    //AudioSource.PlayClipAtPoint(CGame.PrimaryResources.AudioClips[9], mPosition.ToWorldVec3(), 1.0f);
                    _audioSource.PlayOneShot(CGame.PrimaryResources.AudioClips[9]);
                }
                else
                {
                    _audioSource.PlayOneShot(CGame.PrimaryResources.AudioClips[10]);
                }
                //AudioSource.PlayClipAtPoint(CGame.PrimaryResources.AudioClips[10], mPosition.ToWorldVec3(), 1.0f);

                _doorTarget = mDoorAngle;
            }

            if (_doorAngle != mDoorAngle)
            {
                _doorAngle = Mathf.Lerp(_doorAngle, mDoorAngle, 2.0f * Time.deltaTime);
                _Gob.transform.GetChild(1).localScale = new Vector3(1.0f - _doorAngle, 1.0f, 1.0f);
                _Gob.transform.GetChild(2).localScale = new Vector3(1.0f - _doorAngle, 1.0f, 1.0f);
            }

            if (mOwnerID == UserSession.mPlayerIndex)
            {
                CPunchOut.UpdateMesh(_punchOutMesh, _worldView, _Gob.transform.position.ToWorldVec2(), 8.0f);
            }
        }
        else if (mAsset.mItemType == EItemType.SAFE)
        {
            //_textMesh.text = mValue.ToString();
            //_textGob.transform.position = mBounds.center + new Vector3(0.0f, 1.5f, 0.0f);
            //_textGob.transform.rotation = Quaternion.Euler(0, Time.time * 50.0f, 0);
        }

        //if (_itemView.mTaggedUsable && (tp == CEntity.EType.T_ITEM_DESK || tp == CEntity.EType.T_ITEM_FOOD || tp == CEntity.EType.T_ITEM_REST || tp == CEntity.EType.T_ITEM_SAFE))
        //CDebug.DrawXRect(_itemView.mBounds.center, 0.5f, 0.5f, Color.blue);

        //if (_itemView.mOwnerID != -1 && tp == CEntity.EType.T_ITEM_SAFE)
        //CDebug.DrawXRect(_itemView.mBounds.center, 0.2f, 0.2f, _itemView.mWorld.mPlayers[_itemView.mOwnerID].mColor);

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


        /*
         * // UI Space Snippet.
         * 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;
         */
    }