Exemplo n.º 1
0
    private void SpawnOneIceLice(string npcId, Formation formationScript)
    {
        GameObject newSpawn = Instantiate(IceLicePrefab, transform.position, Quaternion.identity).gameObject;

        newSpawn.SendMessage(Constants.METHOD_SET_NPC_ID, npcId, SendMessageOptions.DontRequireReceiver);
        newSpawn.SendMessage(Constants.METHOD_SET_FORMATION_SCRIPT, formationScript, SendMessageOptions.DontRequireReceiver);
        formationScript.AddMember(newSpawn);
    }
    //FixedUpdate to avoid laggy movement (look for alternatives)
    void FixedUpdate()
    {
        if (player == null)
        {
            return;
        }
        if (Mathf.Abs(player.position.z - transform.position.z) >= detectionRange)
        {
            return;
        }


        formation.AddMember(transform);

        if (moveComponent != null)
        {
            var moveTarget = formation.GetTargetPosition(transform);
            if (moveTarget != null)
            {
                moveComponent.MoveTo(moveTarget.position);
            }
            moveComponent.LookAt(player.position);
        }
    }
Exemplo n.º 3
0
        public override void OnInspectorGUI()
        {
            GUILayout.BeginVertical("Box");
            EditorGUILayout.BeginHorizontal();
            var textAsset = _formation.textAsset;

            _formation.textAsset = (TextAsset)EditorGUILayout.ObjectField("Config File",
                                                                          textAsset, typeof(TextAsset), false);
            if (_formation.members.Count == 0 && _formation.textAsset != null || textAsset != _formation.textAsset)
            {
                _formation.RemoveChildren();
                try
                {
                    var data = JsonMapper.ToObject <FormationSerializeData>(_formation.textAsset.text);
                    if (data != null)
                    {
                        _formation.Type = data.type == 1;
                        int i = 0;
                        foreach (var item in data.offset)
                        {
                            var member = _formation.CreateMember(i, _formation.Type?item.id:_formation.MemberId,
                                                                 new Vector3(item.x, item.y, item.z),
                                                                 new Vector3(item.scaleX, item.scaleY, item.scaleZ));
                            _formation.members.Add(member);
                            i++;
                        }

                        _formation.name = data.teamId.ToString();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            var oldMode = _formation.Type;

            _formation.Type = EditorGUILayout.Toggle("指定模型或不指定模型", _formation.Type);
            EditorGUILayout.EndHorizontal();
            if (oldMode != _formation.Type)
            {
                _formation.RemoveAll();
            }
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("+", GUILayout.Width(40)))
            {
                _formation.AddMember();
            }
            if (GUILayout.Button("Export", GUILayout.Width(80)))
            {
                Export();
            }
            _formation.MemberId = this._formation.Type ? EditorGUILayout.IntField("Default ID", _formation.MemberId) : 0;
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            for (int i = 0; i < _formation.members.Count; i++)
            {
                Member member = _formation.members[i];
                EditorGUILayout.BeginHorizontal();
                member.Transform = (Transform)EditorGUILayout.ObjectField(member.Transform, typeof(Transform), true,
                                                                          GUILayout.Width(120));
                if (_formation.Type)
                {
                    var oldId = member.Id;
                    member.Id = EditorGUILayout.IntField("ID", oldId);
                    if (oldId != member.Id)
                    {
                        member = _formation.ChangeMember(member);
                        if (member != null)
                        {
                            _formation.members[i] = member;
                        }
                    }
                }
                if (GUILayout.Button("-", GUILayout.Width(40)))
                {
                    _formation.RemoveMember(i);
                    break;
                }

                EditorGUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
            EditorUtility.SetDirty(_formation);
        }