示例#1
0
        private static IEnumerable <Command> ValidateOfSet(ProcedureParser context, string target, string subTarget)
        {
            List <Command> ret = new List <Command>();

            ret.Add(new Command(DefaultCommandType.Set, target, subTarget));
            CustomPath         path       = new CustomPath(target);
            IProcedureParsable tempTarget = CustomPath.FindAssetWithPath(path);

            if (tempTarget == null)
            {
                if (context.WillBeCreated(new CustomPath(path.FilePath)))
                {
                    Command buff = ret[0];
                    buff.PastValue = Command.NaN;
                    ret[0]         = buff;
                    return(ret);
                }
                ret.Clear();
                ret.Add(new Command(DefaultCommandType.Log, "CannotFoundTarget", $"Set {target} into {subTarget}"));
                return(ret);
            }
            if (path.FromLast(1).StartsWith(CustomPath.RefPrefix))
            {
                string tempValue = tempTarget.Get($"{path.FromLast(1)}/{path.FromLast(0)}");
                if (tempValue == subTarget)
                {
                    ret.Clear();
                }
                else
                {
                    Command buff = ret[0];
                    buff.PastValue = tempValue;
                    ret[0]         = buff;
                }
            }
            else
            {
                string tempValue = tempTarget.Get(path.FromLast(0));
                if (tempValue == subTarget)
                {
                    ret.Clear();
                }
                else
                {
                    Command buff = ret[0];
                    buff.PastValue = tempValue;
                    ret[0]         = buff;
                }
            }
            return(ret);
        }
示例#2
0
        private static IEnumerable <Command> ReactionOfSet(ProcedureParser context, string target, string subTarget)
        {
            List <Command>     ret        = new List <Command>();
            CustomPath         path       = new CustomPath(target);
            IProcedureParsable tempTarget = CustomPath.FindAssetWithPath(path);

            if (tempTarget == null)
            {
                ret.Add(new Command(DefaultCommandType.Log, "CannotFoundTarget", $"Set {target} into {subTarget}"));
                return(ret);
            }

            if (path.FromLast(1).StartsWith(CustomPath.RefPrefix))
            {
                tempTarget.Set($"{path.FromLast(1)}/{path.FromLast(0)}", subTarget);
            }
            else
            {
                tempTarget.Set(path.FromLast(0), subTarget);
            }
            return(null);
        }
        private IEnumerable <Command> ReactionOfCreate(ProcedureParser context, string target, string subTarget)
        {
            List <Command>     ret         = new List <Command>();
            IProcedureParsable targetAsset = CreateNewObject(target);
            CustomPath         targetPath  = new CustomPath(subTarget);
            CustomPath         assetPath   = null;

            {
                int altIndex = 0;
                for (; altIndex < targetPath.Length; altIndex++)
                {
                    if (targetPath.FromLast(altIndex).Contains(CustomPath.ExtensionDiff))
                    {
                        break;
                    }
                }
                assetPath = targetPath.GenerateHigherPath(altIndex);
            }
            Debug.LogWarning(assetPath?.FullPath);

            CustomPath tempPath = new CustomPath(Empty);

            for (int i = 0; i < assetPath.Length - 1; i++)
            {
                tempPath = tempPath.GenerateLowerPath(assetPath[i]);
                if (!AssetDatabase.IsValidFolder(tempPath.FullPath))
                {
                    Debug.Log($"{tempPath} creating directory");
                    AssetDatabase.CreateFolder(tempPath.GenerateHigherPath(1).FullPath, tempPath.FromLast(0));
                }
            }
            if (targetAsset is ScriptableObject)
            {
                AssetDatabase.CreateAsset(targetAsset as ScriptableObject, assetPath.FullPath);
                targetAsset.InitializeAsset();
            }
            else if (targetAsset is Component)
            {
                targetAsset.InitializeAsset();
                PrefabUtility.SaveAsPrefabAsset((targetAsset as Component).gameObject, assetPath.FullPath);
                Object.DestroyImmediate((targetAsset as Component).gameObject);
            }
            else
            {
                ret.Add(new Command(DefaultCommandType.Log, "Invalid Type"));
                return(ret);
            }

            return(null);
        }
        public string GenerateTooltipText(Command com)
        {
            string ret = string.Empty;

            switch (com.Type)
            {
            case DefaultCommandType.Log:
                ret += $"<color=red>{com.Target}</color>";
                break;

            case DefaultCommandType.Create:
                ret += $"<color=green>{com.Target}</color>";
                break;

            case DefaultCommandType.Move:
            {
                CustomPath targetPath = new CustomPath(com.SubTarget);
                if (com.PastValue == MoveCommand.MoveTo)
                {
                    ret += $"<color=#4080FF>{com.PastValue} {com.SubTarget}</color>";
                }
                else
                {
                    ret += $"<color=#4080FF>{com.PastValue} {com.Target}</color>";
                }
            }
            break;

            case DefaultCommandType.Set:
            {
                CustomPath targetPath = new CustomPath(com.Target);
                ret += $"<color={(com.PastValue==Command.NaN?"green":"black")}>{targetPath.FromLast(0).Split('_').Last()} : {com.PastValue} -> {com.SubTarget}</color>";
            }
            break;
            }
            return(ret);
        }