コード例 #1
0
    /// <summary>
    /// Clones an action using a memberwise clone (but clears out the child action list).
    /// This is only used by the pluggable factory to be able to create new cinematic actions
    /// without requiring extra setup code. Technically this can be overridden, but use-cases
    /// of that are sparse.
    /// </summary>
    /// <returns></returns>
    public virtual object Clone()
    {
        CinematicAction clone = (CinematicAction)this.MemberwiseClone();

        clone.mChildActions = new List <CinematicAction>();

        return((object)clone);
    }
コード例 #2
0
    public CinematicAction GetRootAction()
    {
        CinematicAction parent = this;

        while (parent.parentAction != null)
        {
            parent = parent.parentAction;
        }

        return(parent);
    }
コード例 #3
0
    private int GetChildrenOfType <T>(T[] result, CinematicAction root, int count) where T : CinematicAction
    {
        if (root is T)
        {
            result[count] = root as T;
            count++;
        }

        for (int i = 0; i < root.mChildActions.Count; ++i)
        {
            CinematicAction child = root.mChildActions[i];
            count = GetChildrenOfType <T>(result, child, count);
        }

        return(count);
    }
コード例 #4
0
    // Allow us to navigate the parents/children of CinematicActions easily
    public T GetParentOfType <T>() where T : CinematicAction
    {
        CinematicAction parent = this;

        while (parent != null)
        {
            if (parent is T)
            {
                return(parent as T);
            }

            parent = parent.parentAction;
        }

        return(null);
    }
コード例 #5
0
    private CinematicAction GetChildWithId(string id, CinematicAction root)
    {
        if (root.id == id)
        {
            return(root);
        }

        for (int i = 0; i < root.mChildActions.Count; ++i)
        {
            CinematicAction child  = root.mChildActions[i];
            CinematicAction result = GetChildWithId(id, child);
            if (result != null)
            {
                return(result);
            }
        }

        return(null);
    }
コード例 #6
0
    private T GetChildOfType <T>(CinematicAction root) where T : CinematicAction
    {
        if (root is T)
        {
            return(root as T);
        }

        for (int i = 0; i < root.mChildActions.Count; ++i)
        {
            CinematicAction child  = root.mChildActions[i];
            CinematicAction result = GetChildOfType <T>(child);
            if (result != null)
            {
                return(result as T);
            }
        }

        return(null);
    }
コード例 #7
0
    public CinematicActionPluggableFactory()
    {
        System.Type[] types = Assembly.GetAssembly(typeof(CinematicAction)).GetTypes();

        for (int i = 0; i < types.Length; ++i)
        {
            System.Type type = types[i];
            if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(CinematicAction)))
            {
                CinematicAction template = (CinematicAction)Activator.CreateInstance(type);
                RegisterActionTemplate(template);

                mAliases.Add(template.actionName, template);

                if (template.aliases != null)
                {
                    for (int aliasIdx = 0; aliasIdx < template.aliases.Length; ++aliasIdx)
                    {
                        mAliases.Add(template.aliases[aliasIdx], template);
                    }
                }
            }
        }
    }
コード例 #8
0
 public Coroutine PlayAction(CinematicAction action)
 {
     return(StartCoroutine(action.Play(this)));
 }
コード例 #9
0
    public override void AddChildAction(CinematicAction childAction)
    {
        base.AddChildAction(childAction);

        childAction.shouldYield = (childAction.shouldYield || mDefaultYield);
    }
コード例 #10
0
    public CinematicAction ConstructNewActionByName(string name)
    {
        CinematicAction newAction = (CinematicAction)mAliases[name].Clone();

        return(newAction);
    }
コード例 #11
0
 public void RegisterActionTemplate(CinematicAction actionTemplate)
 {
     mRegisteredActionTemplates.Add(actionTemplate);
 }
コード例 #12
0
    public List <CinematicAction> ParseCinematic(string blob)
    {
        List <CinematicAction> actions        = new List <CinematicAction>();
        List <CinematicAction> subActionStack = new List <CinematicAction>();
        CinematicAction        previousAction = null;
        bool inMultiLineComment = false;

        string[] lines = blob.Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries);
        for (int i = 0; i < lines.Length; ++i)
        {
            string line = lines[i].Trim();
            if (line.Length == 0 || line.StartsWith("//"))
            {
                // do nothing - ignore the line
            }
            else if (line.StartsWith("/*"))
            {
                inMultiLineComment = true;
            }
            else if (line.EndsWith("*/"))
            {
                inMultiLineComment = false;
            }
            else if (inMultiLineComment)
            {
                // do nothing - we're in a comment
            }
            else if (line == "{")
            {
                Debug.Assert(previousAction != null);
                subActionStack.Add(previousAction);
            }
            else if (line == "}")
            {
                subActionStack.RemoveAt(subActionStack.Count - 1);
            }
            else
            {
                string[] symbols = line.Split(new char[] { ' ' }, 2, System.StringSplitOptions.RemoveEmptyEntries);

                string actionName = symbols[0].Trim();

                if (!mActionFactory.ActionExists(actionName))
                {
                    Debug.LogError("Action does not exist: " + actionName);
                }

                CinematicAction newAction = mActionFactory.ConstructNewActionByName(actionName);
                Debug.Assert(newAction != null, actionName);

                if (symbols.Length > 1)
                {
                    List <string> parameterList = SplitParameterList(symbols[1].Trim());

                    bool simpleParameter = (parameterList.Count == 1 && !parameterList[0].Contains(":"));

                    Dictionary <string, string> parameters = new Dictionary <string, string>();
                    newAction.alias = actionName;

                    if (simpleParameter)
                    {
                        parameters.Add(newAction.simpleParameterName, parameterList[0]);
                    }
                    else
                    {
                        for (int parameterIdx = 0; parameterIdx < parameterList.Count; ++parameterIdx)
                        {
                            string[] parameterKeyValue = parameterList[parameterIdx].Split(new char[] { ':' });
                            string   key   = parameterKeyValue[0].Trim();
                            string   value = parameterKeyValue[1].Trim();
                            parameters.Add(key, value);
                        }
                    }

                    newAction.SetParameters(parameters);
                }

                previousAction = newAction;

                if (subActionStack.Count > 0)
                {
                    CinematicAction parent = subActionStack[subActionStack.Count - 1];
                    newAction.parentAction = parent;

                    parent.AddChildAction(newAction);
                }
                else
                {
                    actions.Add(newAction);
                }
            }
        }

        return(actions);
    }
コード例 #13
0
 public virtual void AddChildAction(CinematicAction childAction)
 {
     mChildActions.Add(childAction);
 }