public override void ShowMenu(SerializedProperty property)
    {
        string directory = property.stringValue;
        string sel       = "";

        directory = KingUtil.AbsolutePath(directory);
        if (string.IsNullOrEmpty(directory))
        {
            directory = FileSelectAttribute.directory;
        }
        if (FileSelectAttribute.dialog == FileSelectAttribute.DialogType.Load)
        {
            sel = EditorUtility.OpenFilePanel(FileSelectAttribute.title, directory,
                                              FileSelectAttribute.extensions);
        }
        else
        {
            sel = EditorUtility.SaveFilePanel(FileSelectAttribute.title, directory,
                                              FileSelectAttribute.defaultName, FileSelectAttribute.extensions);
        }

        if (!string.IsNullOrEmpty(sel))
        {
            selectVal  = FileSelectAttribute.absolute ? KingUtil.AbsolutePath(sel): KingUtil.RelativePath(sel);
            selectPath = property.propertyPath;
        }
    }
    /// <summary>
    /// Field to select the path to the file
    /// </summary>
    /// <param name="dialog">Dialogue type</param>
    /// <param name="title">Dialogue caption</param>
    /// <param name="directory">Default directory</param>
    /// <param name="extensions">File extensions</param>
    /// <param name="defaultName">Default file name</param>
    public FileSelectAttribute(DialogType dialog, string title = "", string directory = "", string extensions = "", string defaultName = "")
    {
        this.dialog = dialog;
        if (!string.IsNullOrEmpty(title))
        {
            this.title = title;
        }

        if (!string.IsNullOrEmpty(directory))
        {
            this.directory = directory;
        }
        else
        {
            this.directory = KingUtil.AppPath("");
        }

        if (!string.IsNullOrEmpty(extensions))
        {
            this.extensions = extensions;
        }
        if (!string.IsNullOrEmpty(defaultName))
        {
            this.defaultName = defaultName;
        }
    }
    public override void ShowMenu(SerializedProperty property)
    {
        string folder = property.stringValue;
        string sel    = "";

        folder = string.IsNullOrEmpty(folder) ? "" : Path.GetDirectoryName(Path.GetFullPath(folder) + Path.DirectorySeparatorChar);
        if (string.IsNullOrEmpty(folder))
        {
            folder = FolderSelectAttribute.folder;
        }
        if (FolderSelectAttribute.dialog == FolderSelectAttribute.DialogType.Load)
        {
            sel = EditorUtility.OpenFolderPanel(FolderSelectAttribute.title, folder,
                                                FolderSelectAttribute.defaultName);
        }
        else
        {
            sel = EditorUtility.SaveFolderPanel(FolderSelectAttribute.title, folder,
                                                FolderSelectAttribute.defaultName);
        }
        if (!string.IsNullOrEmpty(sel))
        {
            selectVal  = FolderSelectAttribute.absolute ? KingUtil.AbsolutePath(sel) : KingUtil.RelativePath(sel);
            selectPath = property.propertyPath;
        }
    }
Beispiel #4
0
        public float CalcDamage(float power, DamageType kind = DamageType.Physics)
        {
            DamageType exposedFilter = Exposed;
            float      damageValue   = 0;
            Dictionary <DamageType, float> results = new Dictionary <DamageType, float>();

            foreach (DamageType s in Enum.GetValues(typeof(DamageType)))
            {
                if ((s & Exposed) > 0)
                {
                    results.Add(s, 0);
                }
            }
            //Считаем повреждения по каждому типу
            foreach (var modificator in modificators)
            {
                if ((modificator.type & exposedFilter) == 0)
                {
                    continue;
                }
                if ((modificator.type & kind) == 0)
                {
                    continue;
                }
                switch (modificator.effect)
                {
                case DamageEffect.OnlyThis:
                    results[modificator.type] = power * modificator.power;
                    exposedFilter            &= ~modificator.type;
                    break;

                case DamageEffect.Add:
                    results[modificator.type] = (results.ContainsKey(modificator.type)? results[modificator.type] : 0) + power * modificator.power;
                    break;

                case DamageEffect.Concurent:
                    if (results.ContainsKey(modificator.type))
                    {
                        results[modificator.type] = Mathf.Max(results[modificator.type], power * modificator.power);
                    }
                    break;
                }
            }
            //Считаем суммарные повреждения
            foreach (var result in results)
            {
                damageValue += result.Value;
            }
            return(KingUtil.Round(damageValue * ScaleDamage, 0.1f));
        }
Beispiel #5
0
    float getValue(Rect position, GUIContent label, float value)
    {
        float left     = rangeAttribute.left;
        float right    = rangeAttribute.right;
        float step     = rangeAttribute.step;
        float newValue = EditorGUI.Slider(position, label, value, left, right);

        if (newValue != left && newValue != right && step > float.Epsilon)
        {
            newValue = newValue - left;
            newValue = KingUtil.Round(newValue, step);
            newValue = newValue + left;
            newValue = Mathf.Clamp(newValue, Mathf.Min(left, right), Mathf.Max(left, right));
        }

        return(newValue);
    }
 /// <summary>
 /// Field to select the path to the folder
 /// </summary>
 /// <param name="dialog">Dialogue type</param>
 /// <param name="title">Dialogue caption</param>
 /// <param name="folder">Default directory</param>
 /// <param name="defaultName">Default folder name</param>
 public FolderSelectAttribute(DialogType dialog, string title = "", string folder = "", string defaultName = "")
 {
     this.dialog = dialog;
     if (!string.IsNullOrEmpty(title))
     {
         this.title = title;
     }
     if (!string.IsNullOrEmpty(folder))
     {
         this.folder = folder;
     }
     else
     {
         this.folder = KingUtil.AppPath("");
     }
     if (!string.IsNullOrEmpty(defaultName))
     {
         this.defaultName = defaultName;
     }
 }
Beispiel #7
0
    /// <summary>
    /// Gets the animator controller.
    /// </summary>
    /// <returns>
    /// The animator controller.
    /// </returns>
    /// <param name='property'>
    /// Property.
    /// </param>

    AnimatorController GetAnimatorController(SerializedProperty property)
    {
        Component component  = null;
        string    sourceName = GetSourceName();

        if (string.IsNullOrEmpty(sourceName))
        {
            component = property.serializedObject.targetObject as Component;
        }
        else
        {
            SerializedProperty source = EditorExt.GetPropertyByName(property, sourceName);
            if (source != null)
            {
                component = source.objectReferenceValue as Component;
            }
            if (component == null)
            {
                component = KingUtil.GetPropertyValue <Animator>(property.serializedObject.targetObject, sourceName);
            }
        }
        if (component == null)
        {
            LogError("Couldn't cast targetObject", property.serializedObject.targetObject);
            return(null);
        }

        Animator anim = component.GetComponent <Animator>();

        if (anim == null)
        {
            LogError("Missing Animator Component", property.serializedObject.targetObject);
            return(null);
        }

        AnimatorController animatorController = anim.runtimeAnimatorController as AnimatorController;

        return(animatorController);
    }
    public override string[] GetOptions()
    {
        string[] propertyList = new string[0];

        if (!string.IsNullOrEmpty(Target))
        {
            Type target = KingUtil.GetType(Target);
            if (null != target)
            {
                List <string> list = new List <string>();
                foreach (FieldInfo field in target.GetFields())
                {
                    if (propertyPopupAttribute.canSet && field.IsInitOnly)
                    {
                        continue;
                    }

                    GUIContent fContent = SetBaseContent(new GUIContent(), field);
                    list.Add(field.Name + (fContent.text != "" ? "(" + fContent.text + ")": ""));
                }
                foreach (PropertyInfo property in target.GetProperties())
                {
                    if (propertyPopupAttribute.canSet && !property.CanWrite)
                    {
                        continue;
                    }

                    GUIContent pContent = SetBaseContent(new GUIContent(), property);
                    list.Add(property.Name + (pContent.text != "" ? "(" + pContent.text + ")" : ""));
                }
                list.Sort();
                propertyList = list.ToArray();
            }
        }
        return(propertyList);
    }
 public override bool CheckCorrect(string selected)
 {
     return(File.Exists(KingUtil.AbsolutePath(selected)));
 }
 public override bool CheckCorrect(string selected)
 {
     return(Directory.Exists(selected) || Directory.Exists(KingUtil.AppPath("") + Path.DirectorySeparatorChar + selected));
 }
    public override void Draw(Rect position, SerializedProperty property, GUIContent label)
    {
        string errorMsg = "";

        if (string.IsNullOrEmpty(propertyValueAttribute.sourceTypeName))
        {
            errorMsg = "Not specified object type as the source.";
        }
        else if (string.IsNullOrEmpty(propertyValueAttribute.sourcePropertyName))
        {
            errorMsg = "There is not setting the name property of the object as a source.";
        }
        else
        {
            //object obj = property.serializedObject.targetObject;
            SerializedProperty prop     = EditorExt.GetPropertyByName(property, propertyValueAttribute.sourceTypeName);
            string             typeName = prop == null ? null: prop.stringValue;

            if (string.IsNullOrEmpty(typeName) || KingUtil.GetType(typeName) == null)
            {
                errorMsg = "Failed to determine the type of object.";
            }
            else
            {
                Type typeObj                    = KingUtil.GetType(typeName);
                SerializedProperty prp          = EditorExt.GetPropertyByName(property, propertyValueAttribute.sourcePropertyName);
                string             propertyName = prp == null ? null : prp.stringValue; //GetPropertyValue(obj, propertyValueAttribute.sourcePropertyName);

                if (string.IsNullOrEmpty(propertyName))
                {
                    errorMsg = "Failed  to determine the property as the source.";
                }
                else
                {
                    Type typeProperty = null;

                    propertyName = KingUtil.GetOnlyName(propertyName);
                    FieldInfo field = typeObj.GetField(propertyName);
                    if (field != null)
                    {
                        typeProperty = field.FieldType;
                    }
                    else
                    {
                        PropertyInfo pInfo = typeObj.GetProperty(propertyName);
                        if (pInfo != null)
                        {
                            typeProperty = pInfo.PropertyType;
                        }
                    }

                    if (typeProperty == null)
                    {
                        LogError("Failed to determine the type property of the source.");
                        return;
                    }
                    else
                    {
                        try
                        {
                            //if (lastTypeProperty != null && lastTypeProperty != typeProperty)
                            //    property.stringValue = "";

                            if (typeProperty == typeof(int))
                            {
                                if (string.IsNullOrEmpty(property.stringValue))
                                {
                                    property.stringValue = "0";
                                }
                                int i = Convert.ToInt32(property.stringValue);
                                i = EditorGUI.IntField(position, label, i);
                                property.stringValue = Prop2Str(i);
                            }
                            else
                            if (typeProperty == typeof(float))
                            {
                                if (string.IsNullOrEmpty(property.stringValue))
                                {
                                    property.stringValue = 0f.ToString();
                                }
                                float f = Convert.ToSingle(property.stringValue);
                                f = EditorGUI.FloatField(position, label, f);
                                property.stringValue = Prop2Str(f);
                            }
                            else
                            if (typeProperty == typeof(string))
                            {
                                property.stringValue = EditorGUI.TextField(position, label, property.stringValue);
                            }
                            else
                            if (typeProperty == typeof(bool))
                            {
                                if (string.IsNullOrEmpty(property.stringValue))
                                {
                                    property.stringValue = bool.FalseString;
                                }

                                bool b = Convert.ToBoolean(property.stringValue);
                                b = EditorGUI.Toggle(position, label, b);
                                property.stringValue = Prop2Str(b);
                            }
                            else if (typeProperty.IsEnum)
                            {
                                if (string.IsNullOrEmpty(property.stringValue))
                                {
                                    property.stringValue = Enum.GetValues(typeProperty).GetValue(0).ToString();
                                }

                                int e = (int)Enum.Parse(typeProperty, property.stringValue);

                                object o = EditorGUI.EnumPopup(position, label, Enum.ToObject(typeProperty, e) as Enum);
                                e = (int)o;
                                property.stringValue = Prop2Str(Enum.Parse(typeProperty, e.ToString()));
                            }
                            else
                            {
                                errorMsg = "No support.";
                            }
                        }
                        catch (Exception)
                        {
                            property.stringValue = "";
                        }

                        //lastTypeProperty = typeProperty;
                    }
                }
            }
        }

        if (!string.IsNullOrEmpty(errorMsg))
        {
            Rect  rect     = EditorGUI.PrefixLabel(position, label);
            Color oldColor = GUI.color;
            GUI.color = Color.grey;
            EditorGUI.LabelField(rect, errorMsg);
            GUI.color = oldColor;
        }
    }