示例#1
0
        public void CopyFromActionList(ActionList actionList)
        {
            isSkippable    = actionList.isSkippable;
            actionListType = actionList.actionListType;
            useParameters  = actionList.useParameters;

            // Copy parameters
            parameters = new List <ActionParameter>();
            parameters.Clear();
            foreach (ActionParameter parameter in actionList.parameters)
            {
                parameters.Add(new ActionParameter(parameter, true));
            }

            // Actions
            actions = new List <Action>();
            actions.Clear();

            Vector2 firstPosition = new Vector2(14f, 14f);

            foreach (Action originalAction in actionList.actions)
            {
                if (originalAction == null)
                {
                    continue;
                }

                AC.Action duplicatedAction = Object.Instantiate(originalAction) as AC.Action;

                if (actionList.actions.IndexOf(originalAction) == 0)
                {
                    Rect newRect = new Rect(firstPosition, duplicatedAction.NodeRect.size);
                    duplicatedAction.NodeRect = newRect;
                }
                else
                {
                    Rect newRect = new Rect(originalAction.NodeRect.position, duplicatedAction.NodeRect.size);
                    duplicatedAction.NodeRect = newRect;
                }

                duplicatedAction.isAssetFile = true;
                duplicatedAction.AssignConstantIDs();
                duplicatedAction.isMarked = false;
                duplicatedAction.ClearIDs();
                duplicatedAction.parentActionListInEditor = null;

                duplicatedAction.hideFlags = HideFlags.HideInHierarchy;

                AssetDatabase.AddObjectToAsset(duplicatedAction, this);
                AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(duplicatedAction));
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();

                actions.Add(duplicatedAction);
            }
        }