summaryrefslogtreecommitdiff
path: root/Erika/Assets/Scripts/Test2/TestErika.cs
blob: e21fe75e28563ed9382855378833e68200e17346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class UnitSetUp
{
    public UnitActionData actionData; // 动作配置

    public GameObject unitControllerPrefab;

    public GameObject unitPrefab;

    public RuntimeAnimatorController animController;

    public string unitFolder;

    [HideInInspector]
    public GameObject unit;

    [HideInInspector]
    public GameObject unitController;

    [HideInInspector]
    public UnitController owner;
}

public class TestErika : SingletonMB<TestErika>
{
    public UnitSetUp erika;
    public UnitSetUp monster;
    public GameObject unitEffect;

    protected override void Awake()
	{
        base.Awake();
        SetupErika();
        SetupMonster();
        UnitImageEffect.effectPlane = unitEffect;
    }

    private void Update()
    {
        if (Input.GetKeyDown("r"))
        {
            erika.unitController.transform.position = Vector3.zero;
            erika.unitController.transform.rotation = Quaternion.identity;

            monster.unitController.transform.position = new Vector3(2, 0, 0);
            monster.unitController.transform.rotation = Quaternion.Euler(0, 180, 0);
        }
    }

    void SetupErika()
    {
        erika.unitController = GameObject.Instantiate(erika.unitControllerPrefab);
        erika.unitController.transform.position = Vector3.zero;
        erika.unitController.transform.rotation = Quaternion.identity;

        erika.unit = GameObject.Instantiate(erika.unitPrefab);
		erika.unit.transform.position = Vector3.zero;
		erika.unit.transform.rotation = Quaternion.Euler(0, 90, 0);
        erika.unit.transform.SetParent(erika.unitController.transform);

        UnitController unitCtr = erika.unitController.GetOrAddComponent<UnitController>();
        unitCtr.Initialize(erika.unit, erika.unitFolder);

        UnitRootMotion unitRootMotion = unitCtr.unitRootMotion;

        RootMotionProxy rootMotionProxy = erika.unit.GetOrAddComponent<RootMotionProxy>();

		AnimatorOverrideController overrideController = new AnimatorOverrideController(erika.animController);
		overrideController.name = "Override Controller";
		var itAction = erika.actionData.actions.GetEnumerator();
		while(itAction.MoveNext())
		{
			string state = itAction.Current.Key;
			string path = itAction.Current.Value.animationPath;
			var clip = ResourceManager.Instance.LoadAsset<AnimationClip>(path);
			overrideController[state] = clip;
		}
		erika.unit.GetComponent<Animator>().runtimeAnimatorController = overrideController;

        unitCtr.pcState.ChangeState(PCState.EUnitState.Idle, new PCState.IdleParam(), true);

		////////////////////////////////

		UnitManager.Instance.SetPlayerCharacter(unitCtr as PCController);
    }

    void SetupMonster()
    {
        monster.unitController = GameObject.Instantiate(monster.unitControllerPrefab);
        monster.unitController.transform.position = Vector3.zero;
        monster.unitController.transform.rotation = Quaternion.identity;

        monster.unit = GameObject.Instantiate(monster.unitPrefab);
        monster.unit.transform.rotation = Quaternion.Euler(0, 90, 0);
        monster.unit.transform.SetParent(monster.unitController.transform);

        UnitController unitCtr = monster.unitController.GetOrAddComponent<UnitController>();
        unitCtr.Initialize(monster.unit, monster.unitFolder);

        UnitRootMotion unitRootMotion = unitCtr.unitRootMotion;

        RootMotionProxy rootMotionProxy = monster.unit.GetOrAddComponent<RootMotionProxy>();

        Animator animator = monster.unit.GetComponent<Animator>();
        AnimatorOverrideController animCtr = new AnimatorOverrideController(monster.animController);
        animCtr.name = monster.unitPrefab.name + " Override Controller";
        animator.runtimeAnimatorController = animCtr;

        unitCtr.monsterState.ChangeState(MonsterState.EUnitState.Idle, new MonsterState.IdleParam(), true);

        monster.unitController.transform.position = new Vector3(2, 0, 0);
        monster.unitController.transform.rotation *= Quaternion.Euler(0, 180, 0);

        monster.owner = unitCtr;
    }

}