Exemple #1
0
        /**
         * <summary>Creates a new instance of the 'Character: Hold object' Action with key variables already set.</summary>
         * <param name = "characterToUpdate">The character who will hold the object</param>
         * <param name = "objectToHold">The object that the character is to hold</param>
         * <param name = "handToUse">Which hand to place the object in (Left, Right)</param>
         * <param name = "localEulerAngles">The euler angles to apply locally to the object being held</param>
         * <returns>The generated Action</returns>
         */
        public static ActionCharHold CreateNew(Char characterToUpdate, GameObject objectToHold, Hand handToUse, Vector3 localEulerAngles = default(Vector3))
        {
            ActionCharHold newAction = (ActionCharHold)CreateInstance <ActionCharHold>();

            newAction._char            = characterToUpdate;
            newAction.objectToHold     = objectToHold;
            newAction.hand             = handToUse;
            newAction.localEulerAngles = localEulerAngles;
            return(newAction);
        }
	public override void ActionCharHoldRun (ActionCharHold action)
	{
		if (action.objectToHold)
		{
			Transform handTransform;
			
			if (action.hand == ActionCharHold.Hand.Left)
			{
				handTransform = action._char.leftHandBone;
			}
			else
			{
				handTransform = action._char.rightHandBone;
			}
			
			if (handTransform)
			{
				action.objectToHold.transform.parent = handTransform;
				action.objectToHold.transform.localPosition = Vector3.zero;
				
				if (action.rotate90)
				{
					action.objectToHold.transform.localEulerAngles = new Vector3 (0f, 0f, 90f);
				}
				else
				{
					action.objectToHold.transform.localEulerAngles = Vector3.zero;
				}
			}
			else
			{
				Debug.Log ("Cannot parent object - no hand bone found.");
			}
		}
	}
	public override void ActionCharHoldGUI (ActionCharHold action, List<ActionParameter> parameters)
	{
		#if UNITY_EDITOR

		action.objectToHoldParameterID = Action.ChooseParameterGUI ("Object to hold:", parameters, action.objectToHoldParameterID, ParameterType.GameObject);
		if (action.objectToHoldParameterID >= 0)
		{
			action.objectToHoldID = 0;
			action.objectToHold = null;
		}
		else
		{
			action.objectToHold = (GameObject) EditorGUILayout.ObjectField ("Object to hold:", action.objectToHold, typeof (GameObject), true);
			
			action.objectToHoldID = action.FieldToID (action.objectToHold, action.objectToHoldID);
			action.objectToHold = action.IDToField (action.objectToHold, action.objectToHoldID, false);
		}

		action.hand = (ActionCharHold.Hand) EditorGUILayout.EnumPopup ("Hand:", action.hand);
		action.rotate90 = EditorGUILayout.Toggle ("Rotate 90 degrees?", action.rotate90);

		if (GUI.changed)
		{
			EditorUtility.SetDirty (action);
		}

		#endif
	}
	public virtual void ActionCharHoldRun (ActionCharHold action)
	{ }
	public virtual void ActionCharHoldGUI (ActionCharHold action, List<ActionParameter> parameters)
	{
		#if UNITY_EDITOR
		EditorGUILayout.HelpBox ("This Action is not compatible with this Character's Animation Engine.", MessageType.Info);
		#endif
	}