Example #1
0
 private void FindComponents <T>(ref T[] aTargetList)
 {
     for (int i = 0, n = components.Length; i < n; i++)
     {
         if (components[i] is T && components[i].IsExists)
         {
             AntArray.Add <T>(ref aTargetList, (T)components[i]);
         }
     }
 }
        private void OnAddCondition(object aValue)
        {
            var item = new AntAIScenarioItem
            {
                id    = _scenario.conditions.GetIndex(aValue.ToString()),
                value = true
            };

            AntArray.Add(ref _goal.conditions, item);
        }
Example #3
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            GUILayout.BeginVertical(EditorStyles.helpBox);
            AntPoolList newPool = null;

            newPool = EditorGUILayout.ObjectField("Add Pool List", newPool, typeof(AntPoolList), true) as AntPoolList;
            if (newPool != null)
            {
                if (!AlreadyAdded(newPool))
                {
                    AntArray.Add <AntPoolList>(ref _self.pools, newPool);
                }
                else
                {
                    EditorUtility.DisplayDialog("Oops!", string.Format("Object `{0}` already added to the pool list!", newPool.name), "Ok");
                }
            }

            GUILayout.Space(3.0f);
            if (_self.pools.Length > 0)
            {
                EditorGUI.indentLevel++;
                int delIndex = -1;
                for (int i = 0, n = _self.pools.Length; i < n; i++)
                {
                    GUILayout.BeginHorizontal();

                    _self.pools[i] = EditorGUILayout.ObjectField(_self.pools[i], typeof(AntPoolList), true) as AntPoolList;

                    if (GUILayout.Button("", "OL Minus", GUILayout.MaxWidth(18.0f), GUILayout.MaxHeight(16.0f)))
                    {
                        delIndex = i;
                    }

                    GUILayout.EndHorizontal();
                }

                if (delIndex > -1)
                {
                    AntArray.RemoveAt <AntPoolList>(ref _self.pools, delIndex);
                }
                EditorGUI.indentLevel--;
            }
            else
            {
                EditorGUILayout.LabelField("<Empty>", EditorStyles.centeredGreyMiniLabel);
            }
            GUILayout.Space(3.0f);
            GUILayout.EndVertical();

            _self.countPerStep = EditorGUILayout.IntField("Count Per Step", _self.countPerStep);
        }
        private void OnAddPostCondition(object aValue)
        {
            var item = new AntAIScenarioItem
            {
                id    = _scenario.conditions.GetIndex(aValue.ToString()),
                value = true
            };

            AntArray.Add(ref _action.post, item);
            EditorUtility.SetDirty(Scenario);
        }
        private void AddConditionHandler(object aValue)
        {
            var item = new AntAIScenarioItem
            {
                id    = _scenario.conditions.GetIndex(aValue.ToString()),
                value = true
            };

            AntArray.Add(ref _worldState.list, item);
            EditorUtility.SetDirty(_scenario);
        }
        public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();

            var prevKey = _self.key;

            _self.key = EditorGUILayout.TextField("Animation Key", _self.key);

            GUILayout.BeginVertical(EditorStyles.helpBox);
            {
                Sprite newSprite = null;
                newSprite = (Sprite)EditorGUILayout.ObjectField("Add Frame", newSprite, typeof(Sprite), false, GUILayout.MaxHeight(16.0f));
                if (newSprite != null)
                {
                    if (_self.frames == null)
                    {
                        _self.frames = new Sprite[0];
                    }

                    AntArray.Add <Sprite>(ref _self.frames, newSprite);
                }

                if (_self.frames != null)
                {
                    int    delIndex = -1;
                    Sprite prev;
                    for (int i = 0, n = _self.frames.Length; i < n; i++)
                    {
                        GUILayout.BeginHorizontal();
                        {
                            prev            = _self.frames[i];
                            _self.frames[i] = (Sprite)EditorGUILayout.ObjectField(_self.frames[i], typeof(Sprite), false);
                            if (GUILayout.Button("", "OL Minus", GUILayout.MaxWidth(20.0f), GUILayout.MaxHeight(20.0f)))
                            {
                                delIndex = i;
                            }
                        }
                        GUILayout.EndHorizontal();
                    }

                    if (delIndex > -1)
                    {
                        AntArray.RemoveAt <Sprite>(ref _self.frames, delIndex);
                    }
                }
            }
            GUILayout.EndVertical();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(target);
            }
        }
 private void AddAllConditionsHandler(object aValue)
 {
     _worldState.list = new AntAIScenarioItem[0];
     for (int i = 0, n = _scenario.conditions.list.Length; i < n; i++)
     {
         AntArray.Add(ref _worldState.list, new AntAIScenarioItem
         {
             id    = _scenario.conditions.GetIndex(_scenario.conditions.list[i].name),
             value = true
         });
     }
     EditorUtility.SetDirty(_scenario);
 }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            EditorGUI.BeginChangeCheck();

            string[] anims = new string[_self.animations.Length];
            for (int i = 0, n = _self.animations.Length; i < n; i++)
            {
                anims[i] = (_self.animations[i] != null)
                                        ? _self.animations[i].key
                                        : "<Missed Animation>";
            }

            if (anims.Length == 0)
            {
                AntArray.Add(ref anims, "<None>");
            }

            int index = 0;

            index = System.Array.FindIndex(anims, x => string.Equals(x, _self.initialAnimation));
            index = (index < 0) ? 0 : index;
            index = EditorGUILayout.Popup("Initial Animation", index, anims);

            if (anims.Length > 0 && !_self.initialAnimation.Equals(anims[index]))
            {
                _self.initialAnimation = anims[index];
            }

            if (_self.animations.Length == 0)
            {
                EditorGUILayout.HelpBox("You must add at least one animation.", MessageType.Warning);
            }

            GUILayout.BeginVertical(EditorStyles.helpBox);
            {
                AntAnimation newAnim = null;
                newAnim = (AntAnimation)EditorGUILayout.ObjectField("Add Animation", newAnim, typeof(AntAnimation), false, GUILayout.MaxHeight(16.0f));
                if (newAnim != null)
                {
                    var foundIndex = System.Array.FindIndex(_self.animations, x => System.Object.ReferenceEquals(x, newAnim));
                    if (foundIndex == -1)
                    {
                        foundIndex = System.Array.FindIndex(_self.animations, x => x.key.Equals(newAnim.key));
                        if (foundIndex == -1)
                        {
                            AntArray.Add <AntAnimation>(ref _self.animations, newAnim);
                        }
                        else
                        {
                            A.Warning($"Animation with `{newAnim.key}` name already exists! Required unique animation names.");
                        }
                    }
                    else
                    {
                        A.Warning($"Animation `{newAnim.name}` already added!");
                    }
                }

                int          delIndex = -1;
                AntAnimation prevAnim = null;
                for (int i = 0, n = _self.animations.Length; i < n; i++)
                {
                    GUILayout.BeginHorizontal();
                    {
                        prevAnim            = _self.animations[i];
                        _self.animations[i] = (AntAnimation)EditorGUILayout.ObjectField(_self.animations[i], typeof(AntAnimation), false);
                        if (GUILayout.Button("", "OL Minus", GUILayout.MaxWidth(20.0f), GUILayout.MaxHeight(20.0f)))
                        {
                            delIndex = i;
                        }
                    }
                    GUILayout.EndHorizontal();
                }

                if (delIndex > -1)
                {
                    AntArray.RemoveAt <AntAnimation>(ref _self.animations, delIndex);
                }
            }
            GUILayout.EndVertical();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(target);
            }
        }
        private void DrawPoolList()
        {
            GUILayout.BeginHorizontal();
            {
                _searchQuery = GUILayout.TextField(_searchQuery, GUI.skin.FindStyle("ToolbarSeachTextField") /*, GUILayout.MinWidth(150.0f)*/);
                if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton") /*, GUILayout.MaxWidth(150.0f)*/))
                {
                    _searchQuery = string.Empty;
                    GUI.FocusControl(null);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginVertical();
            {
                GameObject newObject = null;
                newObject = (GameObject)EditorGUILayout.ObjectField("Drop to Add", newObject, typeof(GameObject), false);
                if (newObject != null)
                {
                    if (!AlreadyAdded(newObject))
                    {
                        AntArray.Add <AntPoolList.Item>(ref _self.items, new AntPoolList.Item
                        {
                            prefab      = newObject,
                            initialSize = 5,
                            isGrow      = true,
                            maxGrowing  = 20,
                            isOpened    = true
                        });
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("Oops!", string.Format("Object `{0}` already added to the pool list!", newObject.name), "Ok");
                    }
                }
            }
            GUILayout.EndVertical();

            if (_self.items.Length == 0)
            {
                EditorGUILayout.LabelField("The Pool List is Empty.");
            }
            else
            {
                GUILayout.BeginVertical();
                {
                    Color            c = GUI.color;
                    AntPoolList.Item curItem;
                    for (int i = _self.items.Length - 1; i >= 0; i--)
                    {
                        curItem = _self.items[i];
                        if (curItem.prefab == null || (curItem.prefab != null && curItem.prefab.name.ToLower().Contains(_searchQuery.ToLower())))
                        {
                            EditorGUI.indentLevel++;
                            if (curItem.prefab == null)
                            {
                                GUI.color = Color.red;
                            }
                            GUILayout.BeginVertical(EditorStyles.helpBox);
                            GUI.color = c;

                            GUILayout.BeginHorizontal();
                            {
                                curItem.isOpened = (curItem.prefab != null)
                                                                        ? EditorGUILayout.Foldout(curItem.isOpened, curItem.prefab.name, true)
                                                                        : curItem.isOpened = EditorGUILayout.Foldout(curItem.isOpened, "<Missed Prefab>", true);

                                EditorGUILayout.LabelField(string.Format("{0}", curItem.initialSize), GUILayout.MaxWidth(60.0f));

                                if (_removeIndex == i && !_confirmRemove)
                                {
                                    GUI.color      = Color.red;
                                    _confirmRemove = GUILayout.Button("Delete?", GUILayout.MaxWidth(70.0f), GUILayout.MaxHeight(16.0f));

                                    GUI.color = Color.green;
                                    if (GUILayout.Button("X", GUILayout.MaxWidth(18.0f), GUILayout.MaxHeight(16.0f)))
                                    {
                                        _removeIndex = -1;
                                    }

                                    GUI.color = c;
                                }
                                else
                                {
                                    if (GUILayout.Button("X", GUILayout.MaxWidth(18.0f), GUILayout.MaxHeight(16.0f)))
                                    {
                                        _removeIndex = i;
                                    }
                                }

                                GUI.color = c;
                            }
                            GUILayout.EndHorizontal();

                            if (curItem.isOpened)
                            {
                                GUILayout.Space(2.0f);
                                EditorGUI.indentLevel++;

                                curItem.prefab      = (GameObject)EditorGUILayout.ObjectField("Object Prefab", curItem.prefab, typeof(GameObject), false);
                                curItem.initialSize = EditorGUILayout.IntField("Initial Size", curItem.initialSize);

                                EditorGUI.indentLevel--;
                                GUILayout.Space(2.0f);
                            }

                            _self.items[i] = curItem;
                            EditorGUI.indentLevel--;
                            GUILayout.EndVertical();
                        }
                    }
                }
                GUILayout.EndVertical();

                EditorGUILayout.LabelField(string.Concat("Total Objects: ", _self.items.Length.ToString()));
            }

            if (_removeIndex != 1 && _confirmRemove)
            {
                AntArray.RemoveAt <AntPoolList.Item>(ref _self.items, _removeIndex);
                _confirmRemove = false;
                _removeIndex   = -1;
            }
        }
Example #10
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            EditorGUI.BeginChangeCheck();
            _self.startDelay = EditorGUILayout.FloatField("Start Delay", _self.startDelay);

            GUI.enabled    = !_self.isLooping;
            _self.lifeTime = EditorGUILayout.FloatField("LifeTime", _self.lifeTime);
            GUI.enabled    = true;

            _self.isLooping          = EditorGUILayout.Toggle("Looping", _self.isLooping);
            _self.isAutoPlay         = EditorGUILayout.Toggle("Auto Play", _self.isAutoPlay);
            _self.isAutoReturnToPool = EditorGUILayout.Toggle("Auto Return To Pool", _self.isAutoReturnToPool);
            _self.isAutoRepeat       = EditorGUILayout.Toggle("Auto Repeat", _self.isAutoRepeat);
            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            {
                AntEmitterPreset newObject = null;
                newObject = EditorGUILayout.ObjectField("Drop to Add", newObject, typeof(AntEmitterPreset), false) as AntEmitterPreset;
                if (newObject != null)
                {
                    AntArray.Add <AntEmitterPreset>(ref _self.emitters, newObject);
                }

                int delIndex = -1;
                for (int i = 0, n = _self.emitters.Length; i < n; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        _self.emitters[i] = EditorGUILayout.ObjectField(_self.emitters[i], typeof(AntEmitterPreset), false) as AntEmitterPreset;
                        if (GUILayout.Button("x", GUILayout.Width(16.0f), GUILayout.Height(16.0f)))
                        {
                            delIndex = i;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }

                if (delIndex >= 0)
                {
                    AntArray.RemoveAt <AntEmitterPreset>(ref _self.emitters, delIndex);
                }
            }
            EditorGUILayout.EndVertical();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(target);
            }

            // MARK: Эффекты больше нельзя стартануть напрямую, т.к. они теперь работают через системы.
            // if (Application.isPlaying)
            // {
            //  if (_self.IsPlaying && (_self.isLooping || _self.isAutoRepeat))
            //  {
            //      if (GUILayout.Button("Stop"))
            //      {
            //          _self.Stop();
            //      }
            //  }
            //  else
            //  {
            //      if (GUILayout.Button("Play"))
            //      {
            //          _self.Play();
            //      }
            //  }
            // }
        }
Example #11
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            EditorGUILayout.Separator();
            EditorGUI.BeginChangeCheck();
            GameObject newEffect = null;

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("List of Effects", EditorStyles.boldLabel);
                if (GUILayout.Button("Collapse", EditorStyles.miniButtonLeft))
                {
                    for (int i = 0, n = _self.effects.Length; i < n; i++)
                    {
                        _self.effects[i].isOpened = false;
                    }
                }

                if (GUILayout.Button("Expand", EditorStyles.miniButtonRight))
                {
                    for (int i = 0, n = _self.effects.Length; i < n; i++)
                    {
                        _self.effects[i].isOpened = true;
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            newEffect = (GameObject)EditorGUILayout.ObjectField("Add Effect", newEffect, typeof(GameObject), false);
            if (newEffect != null)
            {
                if (newEffect.GetComponent <AntEffect>() == null)
                {
                    A.Warning("Can't add the effect! Object `{0}` doesn't have a AntEmitterEffect.", newEffect.name);
                }
                else
                {
                    AntArray.Add <AntEffectSpawner.Settings>(ref _self.effects, new AntEffectSpawner.Settings
                    {
                        name                    = newEffect.name,
                        prefab                  = newEffect,
                        kind                    = AntEffectSpawner.EKind.Basic,
                        isAutoPlay              = true,
                        isUpdatePosition        = false,
                        isInheritAngle          = false,
                        isDisableOnInpact       = false,
                        isPlaceToImpactPosition = false,
                        isUseImpactAngle        = false,
                        isImpactOnce            = false,
                        impactLayerMask         = new LayerMask(),
                        delay                   = 0.0f,
                        rndToDelay              = Vector2.zero,
                        lifeTime                = 1.0f,
                        rndToLifeTime           = Vector2.zero,
                        angle                   = 0.0f,
                        offset                  = Vector2.zero,
                        dotColor                = Color.white,
                        isOpened                = true
                    });
                }
            }

            if (_self.effects.Length > 0)
            {
                int   delIndex = -1;
                Color c        = GUI.color;
                AntEffectSpawner.Settings settings;
                for (int i = 0, n = _self.effects.Length; i < n; i++)
                {
                    settings  = _self.effects[i];
                    GUI.color = GUI.color * settings.dotColor;
                    GUILayout.BeginVertical(EditorStyles.helpBox);
                    GUI.color = c;

                    GUILayout.BeginHorizontal();
                    {
                        EditorGUI.indentLevel++;
                        settings.isOpened = EditorGUILayout.Foldout(settings.isOpened, settings.name, true);
                        EditorGUI.indentLevel--;

                        // GUI.color = c * new Color(1.0f, 1.0f, 0.5f);
                        if (GUILayout.Button("", "OL Minus", GUILayout.MaxWidth(16.0f), GUILayout.MaxHeight(16.0f)))
                        {
                            delIndex = i;
                        }
                        // GUI.color = c;
                    }
                    GUILayout.EndHorizontal();

                    if (settings.isOpened)
                    {
                        EditorGUILayout.Space();
                        EditorGUI.indentLevel++;
                        EditorGUILayout.BeginHorizontal();
                        settings.name     = EditorGUILayout.TextField("Name", settings.name);
                        settings.dotColor = EditorGUILayout.ColorField(settings.dotColor, GUILayout.MaxWidth(80.0f));
                        EditorGUILayout.EndHorizontal();
                        settings.prefab = EditorGUILayout.ObjectField("Effect", settings.prefab, typeof(GameObject), true) as GameObject;
                        // settings.kind = (AntEffectSpawner.EKind) EditorGUILayout.EnumPopup("Kind", settings.kind);

                        string tooltip;
                        // if (settings.kind == AntEffectSpawner.EKind.Basic)
                        // {
                        tooltip             = "Проигрывать эффект при создании объекта.";
                        settings.isAutoPlay = EditorGUILayout.Toggle(new GUIContent("Auto Play", tooltip), settings.isAutoPlay);

                        tooltip = "Остановить эффект при столкновении текущего объекта с другим.";
                        settings.isDisableOnInpact = EditorGUILayout.Toggle(new GUIContent("Stop OnCollision", tooltip), settings.isDisableOnInpact);
                        EditorGUILayout.Space();

                        tooltip         = "Смещение источника эффекта относительно владельца.";
                        settings.offset = EditorGUILayout.Vector2Field(new GUIContent("Offset", tooltip), settings.offset);

                        tooltip        = "Угол источника эффекта относительно владельца.";
                        settings.angle = EditorGUILayout.Slider(new GUIContent("Angle", tooltip), settings.angle, -180.0f, 180.0f);
                        EditorGUILayout.Space();

                        tooltip = "Применить угол объекта для эффекта.";
                        settings.isInheritAngle = EditorGUILayout.Toggle(new GUIContent("Inherit Angle", tooltip), settings.isInheritAngle);

                        tooltip = "Применить позицию объекта для эффекта во время анимации.";
                        settings.isUpdatePosition = EditorGUILayout.Toggle(new GUIContent("Update Position", tooltip), settings.isUpdatePosition);
                        EditorGUILayout.Space();
                        // }
                        // else if (settings.kind == AntEffectSpawner.EKind.Physic)
                        // {
                        //  settings.impactLayerMask = AntLayerMask.LayerMaskField("Layer Mask", settings.impactLayerMask);

                        //  tooltip = "Эффект проиграется один раз только при первом столкновении.";
                        //  settings.isImpactOnce = EditorGUILayout.Toggle(new GUIContent("Play Once", tooltip), settings.isImpactOnce);

                        //  tooltip = "Установить эффект в точку столкновения.";
                        //  settings.isPlaceToImpactPosition = EditorGUILayout.Toggle(new GUIContent("Place to Impact Point", tooltip), settings.isPlaceToImpactPosition);

                        //  tooltip = "Применить угол объекта для эффекта.";
                        //  settings.isInheritAngle = EditorGUILayout.Toggle(new GUIContent("Inherit Angle", tooltip), settings.isInheritAngle);

                        //  tooltip = "Применить позицию объекта для эффекта во время анимации.";
                        //  settings.isUseImpactAngle = EditorGUILayout.Toggle(new GUIContent("Use Inpact Angle", tooltip), settings.isUseImpactAngle);

                        //  EditorGUILayout.Space();
                        // }
                        EditorGUI.indentLevel--;

                        GUILayout.BeginVertical(EditorStyles.helpBox);
                        {
                            settings.customDelay = EditorGUILayout.BeginToggleGroup("Custom Delay", settings.customDelay);
                            if (settings.customDelay)
                            {
                                EditorGUILayout.Space();
                                settings.delay      = EditorGUILayout.FloatField("Delay", settings.delay);
                                settings.rndToDelay = EditorGUILayout.Vector2Field("Rnd to Delay", settings.rndToDelay);
                                EditorGUILayout.Space();
                            }
                            EditorGUILayout.EndToggleGroup();
                        }
                        GUILayout.EndVertical();

                        GUILayout.BeginVertical(EditorStyles.helpBox);
                        {
                            settings.customLifeTime = EditorGUILayout.BeginToggleGroup("Custom Life Time", settings.customLifeTime);
                            if (settings.customLifeTime)
                            {
                                EditorGUILayout.Space();
                                settings.lifeTime      = EditorGUILayout.FloatField("Life Time", settings.lifeTime);
                                settings.rndToLifeTime = EditorGUILayout.Vector2Field("Rnd to Life Time", settings.rndToLifeTime);
                                EditorGUILayout.Space();
                            }
                            EditorGUILayout.EndToggleGroup();
                        }
                        GUILayout.EndVertical();
                    }

                    _self.effects[i] = settings;
                    if (Application.isPlaying)
                    {
                        if (GUILayout.Button("Play"))
                        {
                            _self.Play(settings.name);
                        }

                        // EditorGUILayout.LabelField("Debug Settings");
                        // EditorGUILayout.Toggle("Auto Spawn", false);
                        // EditorGUILayout.FloatField("Spawn Delay", _self.)
                    }

                    GUILayout.EndVertical();
                }

                if (delIndex > -1)
                {
                    AntArray.RemoveAt <AntEffectSpawner.Settings>(ref _self.effects, delIndex);
                }
            }
            else
            {
                EditorGUILayout.LabelField("List of Effects is Empty.", EditorStyles.centeredGreyMiniLabel);
            }

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(target);
            }
        }