public override void UpdateMaterialOfEquipment(MaterialInst inst, Renderer[] equipments, string[] avatarPartNames, Texture2D source, Texture2D normal, Color blendColor, CharacterGraphicsQuality quality)
    {
        SharedTextureMaterialInst stmi = inst as SharedTextureMaterialInst;

        Assertion.Check(stmi != null);

        foreach (Renderer r in equipments)
        {
            stmi.SetMaterialOfRenderer(r);
        }
    }
    public void Init(string nickName, string guildName, int characterClass)
    {
        _characterClass = characterClass;
        _uiHPController = GetComponentInChildren <UIHPController>();

        // get hp display components.
        if (_uiHPController != null)
        {
            _uiHPController.DisplayText = nickName;
            _uiHPController.GuildName   = guildName;
            SetHPDisplay(1.0f, 0, false, false);
            SetEnergyDisplay(1);
        }
        // init material.
        // TODO: remove this protection that not necessary.
        if (_materialBuilder != null)
        {
            _materialInst = _materialBuilder.CreateMaterialForBody(_characterRenderers, _baseMaterial, _quality);
            if (_dynamicShadow)
            {
                foreach (Renderer r in _characterRenderers)
                {
                    r.gameObject.layer = LayerMask.NameToLayer("CHARACTER");
                }
            }
        }

        // init animation state machine.
        _animStateMachines = new AnimStateMachine[(int)AnimType.AnimType_Count];
        _animStateMachines[(int)AnimType.AnimType_Normal]        = new NormalAnimStateMachine();
        _animStateMachines[(int)AnimType.AnimType_Move]          = new MoveAnimStateMachine();
        _animStateMachines[(int)AnimType.AnimType_Attack]        = new AttackAnimStateMachine();
        _animStateMachines[(int)AnimType.AnimType_SpecialAttack] = new SpecialAttackStateMachine();
        _animStateMachines[(int)AnimType.AnimType_Charge]        = new ChargeStateMachine();
        _animStateMachines[(int)AnimType.AnimType_Hurt]          = new HurtAnimStateMachine();

        _actionCtrl = GetComponent <ActionController>();

        foreach (AnimStateMachine asm in _animStateMachines)
        {
            asm.Init(_actionCtrl, _animator);
        }
        _currentAnimStateMachine = AnimType.AnimType_Normal;

        _thisRigidBody = rigidbody;
    }
 virtual public void UpdateMaterialOfEquipment(MaterialInst inst, Renderer[] equipments, string[] avatarPartNames, Texture2D source, Texture2D normal, Color blendColor, CharacterGraphicsQuality quality)
 {
 }
Exemple #4
0
    public override void UpdateMaterialOfEquipment(MaterialInst inst, Renderer[] equipments, string[] avatarPartNames, Texture2D source, Texture2D normal, Color blendColor, CharacterGraphicsQuality quality)
    {
        // inst must be type of ModifiableMaterialInst.
        ModifiableMaterialInst mmi = inst as ModifiableMaterialInst;

        Assertion.Check(mmi != null);
        Material sharedMat = mmi.SharedMaterial;

        foreach (Renderer r in equipments)
        {
            r.sharedMaterial = sharedMat;
        }

        // need to instantiate material builder to use camera in it.
        GameObject go = GameObject.Instantiate(gameObject) as GameObject;

        go.transform.localPosition = Vector3.up * instanceHeight;
        instanceHeight            += 100.0f;

        Camera cam = go.GetComponentInChildren <Camera>();

        MeshRenderer[] renderers = go.GetComponentsInChildren <MeshRenderer>();
        Assertion.Check(renderers.Length > 0);
        Material renderMat = renderers[0].sharedMaterial;

        // enable certain pieces by name
        foreach (MeshRenderer r in renderers)
        {
            r.enabled = false;
            foreach (string s in avatarPartNames)
            {
                if (s == r.gameObject.name)
                {
                    r.enabled = true;
                    Assertion.Check(r.sharedMaterial == renderMat); // all pieces use only 1 uniformed material.
                    break;
                }
            }
        }

        // render color texture.
        renderMat.SetTexture("_MainTex", source);
        renderMat.SetTexture("_AlphaTex", null);
        renderMat.SetColor("_BlendColor", blendColor);
        // set target.
        cam.targetTexture = mmi.TargetTexture;
        cam.Render();

        // render normal texture.
        if (normal != null)
        {
            renderMat.SetTexture("_MainTex", normal);
            renderMat.SetTexture("_AlphaTex", null);
            cam.targetTexture = mmi.TargetNormalTexture;
            cam.Render();
        }

        // clean up
        renderMat.SetTexture("_MainTex", null);
        renderMat.SetTexture("_AlphaTex", null);
        cam.targetTexture = null;
        Destroy(go);
    }