public void DoInteraction(AnimatedInteraction newAI) // supply one with the call { currentInteraction = newAI; foreach(AnimationClip ac in currentInteraction.AnimClips) { if(animQueue.Count > 0) RemoveLastAnim(); if(ac != null && body.animation[ac.name] != null) animQueue.Enqueue(ac); else Debug.LogWarning(gameObject.name + " loading null Interaction Animation for " + currentInteraction.Name); } if(baseClip != null) animQueue.Enqueue(baseClip); idleEnabled = false; if(animState == CharacterAnimState.Idle) PlayNext(0.5f); }
public void DoInteraction(string interactionName) { bool found = false; eventScript = null; string argString = ""; if (interactionName.Contains("?")){ // process any affixed parameters, including 'script=', which must appear first if included // arguments should be of the form ?name=value?name=value?name=value // and can be referenced as script arguments within the animationScript as #name. // the expression ?name=value may include ?name=#arg or ?name=%variable and substitution should occur // in the originating script //(not implemented in the first pass) string[] p = interactionName.Split ('?'); interactionName = p[0]; animSpeed = 1; // for overrideing defaults animWeight = 1; animTime = 0; int start=1; if (p[1].ToLower().Contains("script=")){ start=2; string[] q = p[1].Split('='); foreach (InteractionScript IS in animationScriptObject.scripts){ if (IS.name == q[1]){ eventScript = IS; scriptNameOverride = true; } } } // process speed= weight= time= possibly mixing transform... while (start < p.Length){ if (p.Length > start && p[start].ToLower().Contains("speed=")){ string[] q = p[start].Split('='); float.TryParse(q[1],out animSpeed); } if (p.Length > start && p[start].ToLower().Contains("weight=")){ string[] q = p[start].Split('='); float.TryParse(q[1],out animWeight); } if (p.Length > start && p[start].ToLower().Contains("time=")){ string[] q = p[start].Split('='); float.TryParse(q[1],out animTime); } start++; } body.animation[p[0]].speed = animSpeed; body.animation[p[0]].weight = animWeight; // weight gets overridden by crossfade. if (animTime >= 0) // use -1 to keep animation where it is but change it's speed... body.animation[p[0]].time = animTime; // setting this beyond the initial anim event breaks the anim system, we might need to fake the skipped anim event for (int i=start;i<p.Length; i++){ argString += p[i]; if (i<p.Length-1) argString+=" "; } } //Debug.Log ("!!!!!!" + name + " Doing Interaction " + interactionName); for(int c = 0; c < interactions.Count; c++) { if(interactionName == interactions[c].Name) { found = true; currentInteraction = interactions[c]; if(animQueue.Count > 0) RemoveLastAnim(); foreach(AnimationClip ac in interactions[c].AnimClips) { if(ac != null && body.animation[ac.name] != null) // we might have one to load from resources animQueue.Enqueue(ac); else Debug.LogWarning(gameObject.name + " loading null Interaction Animation for " + interactions[c].Name); } if(baseClip != null) animQueue.Enqueue(baseClip); idleEnabled = false; // we now search for a script name==currentAnim when an event is triggered,, so this check may be un needed. /* if (eventScript == null){ // look for a default eventScript matching the animation name foreach (InteractionScript IS in animationScriptObject.scripts){ if (IS.name == interactionName) eventScript = IS; } } */ if(animState == CharacterAnimState.Idle) PlayNext(0.5f); // careful, PlayNext clears eventScript... //return; //we've done one, we should leave now. continue; } } if (found == false) { // see if there's a clip of this name on our animator AnimationClip aClip = null; if (body.animation[interactionName] != null) aClip = body.animation[interactionName].clip; // do we want to be saving animation states ? if (aClip == null){ // or a clip we loaded from resources if (maleClips.ContainsKey (interactionName)){ // have to check based on m/f aClip = maleClips[interactionName]; body.animation.AddClip(aClip,interactionName); } // if so, add it to our animations } if (aClip != null){ // inefficient, but let's see if there's a matching script here for now. //we should look in the resources folder for these, too. if (eventScript == null){ // look for a default eventScript matching the animation name foreach (InteractionScript IS in animationScriptObject.scripts){ if (IS.name == interactionName) eventScript = IS; scriptNameOverride = true; // adding this so playnext doesn't clear. seems wrong. } } if(animQueue.Count > 0) RemoveLastAnim(); animQueue.Enqueue(aClip); if(baseClip != null) animQueue.Enqueue(baseClip); idleEnabled = false; if(animState == CharacterAnimState.Idle) PlayNext(0.5f); // careful, PlayNext clears eventScript... } currentInteraction = null; // do we need to make one of these, or is this what we should save? } if (eventScript != null){ if (argString != ""){ eventScript.startingArgs = argString; // this replaces and overrides any editor supplied values... } // pass along arguments from the script that called this DoInteraction // there may be some confusion here about which script it was. TaskCharacter tc = GetComponent<TaskCharacter>(); ScriptedAction sa = null; if (tc != null) sa=tc.executingScript; if (sa!=null && sa.executedBy!= null){ eventScript.startingArgs += " "+sa.executedBy.GetArgs(); } } }