/// <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); }
public CinematicAction GetRootAction() { CinematicAction parent = this; while (parent.parentAction != null) { parent = parent.parentAction; } return(parent); }
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); }
// 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); }
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); }
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); }
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); } } } } }
public Coroutine PlayAction(CinematicAction action) { return(StartCoroutine(action.Play(this))); }
public override void AddChildAction(CinematicAction childAction) { base.AddChildAction(childAction); childAction.shouldYield = (childAction.shouldYield || mDefaultYield); }
public CinematicAction ConstructNewActionByName(string name) { CinematicAction newAction = (CinematicAction)mAliases[name].Clone(); return(newAction); }
public void RegisterActionTemplate(CinematicAction actionTemplate) { mRegisteredActionTemplates.Add(actionTemplate); }
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); }
public virtual void AddChildAction(CinematicAction childAction) { mChildActions.Add(childAction); }