/** Like SendMessage, except it allows you to pass multiple arguments. */
        public static void SendMessagePlus(this Component component, string name, SendMessageOptions options, params object[] args)
        {
            Type[] types = Type.GetTypeArray (args);

            var behaviours = component.GetComponents<MonoBehaviour> ();
            foreach (var behaviour in behaviours) {
                MethodInfo method = null;
                try {
                    method = behaviour.GetType ().GetMethod (name, types);
                } catch (AmbiguousMatchException e) {
                    Debug.LogError ("More than one method on " + behaviour + " matches: " + e);
                    return;
                } catch (Exception e) {
                    Debug.LogError (e);
                }

                if (method != null) {
                    method.Invoke (behaviour, args);
                    return;
                }
            }

            if (options == SendMessageOptions.RequireReceiver) {
                Debug.LogError ("LPC " + name + " has no receiver!");
            }
        }
Example #2
0
		public override void Reset()
		{
			gameObject = null;
			delivery = MessageType.SendMessage;
			options = SendMessageOptions.DontRequireReceiver;
			functionCall = null;
		}
Example #3
0
 public ActionSendMessage(string targetMessage, object targetParam, SendMessageOptions targetOptions)
     : base()
 {
     message = targetMessage;
     param = targetParam;
     options = targetOptions;
 }
Example #4
0
 public override void Reset()
 {
     gameObject = null;
     delivery = MessageType.SendMessage;
     options = SendMessageOptions.DontRequireReceiver;
     MethodName = "";
 }
Example #5
0
    public static void RootBroadcastMessage(string methodName, object param, SendMessageOptions options)
    {
        if(Main.instance != null)
            Main.instance.BroadcastMessage(methodName, param, options);

        foreach(Transform t in mRoots) {
            t.BroadcastMessage(methodName, param, options);
        }
    }
	//
	//
	//
	public static void SendMessageDownwards(GameObject go, string methodName, object value = null,
	                                        SendMessageOptions options = SendMessageOptions.RequireReceiver)
	{
		go.SendMessage(methodName, value, options);

		Transform transf = go.transform;
		int i;
		for(i = 0; i<transf.childCount; ++i)
		{
			SendMessageDownwards(transf.GetChild(i).gameObject, methodName, value, options);
		}
	}
Example #7
0
	public static void SendMessageForEditor(this MonoBehaviour monoBehaviour, string message, SendMessageOptions option, params object[] arguments) {
		var behaviours = monoBehaviour.GetComponentsInChildren<MonoBehaviour> ();
		bool success = option == SendMessageOptions.DontRequireReceiver;
		var argumentTypes = System.Type.GetTypeArray (arguments);
		for (int i = 0; i < behaviours.Length; i++) {

			//TODO: This should be improved, since it doesn't guarantee that the correct method signature exists
			var meth = behaviours [i].GetType ().GetMethod (
				message, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
			
			if (meth != null) {
				meth.Invoke ((Object)behaviours [i], arguments);
				success = true;
			}					
		}
		if (!success)
			throw new System.ArgumentException ("No object found with function: " + message);			
	}
Example #8
0
 public override void Reset () {
     gameObject = new ConcreteGameObjectVar(this.self);
     methodName = new ConcreteStringVar();
     options = SendMessageOptions.RequireReceiver;
     floatParameter = new ConcreteFloatVar();
     intParameter = new ConcreteIntVar();
     boolParameter = new ConcreteBoolVar();
     stringParameter = new ConcreteStringVar();
     vector3Parameter = new ConcreteVector3Var();
     rectParameter = new ConcreteRectVar();
     colorParameter = new ConcreteColorVar();
     quaternionParameter = new ConcreteQuaternionVar();
     gameObjectParameter = new ConcreteGameObjectVar(this.self);
     textureParameter = new ConcreteTextureVar();
     materialParameter = new ConcreteMaterialVar();
     fsmEventParameter = new ConcreteFsmEvent();
     objectParameter = new ConcreteObjectVar();
     messageType = MessageType.SendMessage;
 }
Example #9
0
    static int SendMessage(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 2)
        {
            Component obj  = (Component)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Component");
            string    arg0 = LuaScriptMgr.GetLuaString(L, 2);
            obj.SendMessage(arg0);
            return(0);
        }
        else if (count == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(Component), typeof(string), typeof(SendMessageOptions)))
        {
            Component          obj  = (Component)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Component");
            string             arg0 = LuaScriptMgr.GetString(L, 2);
            SendMessageOptions arg1 = (SendMessageOptions)LuaScriptMgr.GetLuaObject(L, 3);
            obj.SendMessage(arg0, arg1);
            return(0);
        }
        else if (count == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(Component), typeof(string), typeof(object)))
        {
            Component obj  = (Component)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Component");
            string    arg0 = LuaScriptMgr.GetString(L, 2);
            object    arg1 = LuaScriptMgr.GetVarObject(L, 3);
            obj.SendMessage(arg0, arg1);
            return(0);
        }
        else if (count == 4)
        {
            Component          obj  = (Component)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Component");
            string             arg0 = LuaScriptMgr.GetLuaString(L, 2);
            object             arg1 = LuaScriptMgr.GetVarObject(L, 3);
            SendMessageOptions arg2 = (SendMessageOptions)LuaScriptMgr.GetNetObject(L, 4, typeof(SendMessageOptions));
            obj.SendMessage(arg0, arg1, arg2);
            return(0);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: Component.SendMessage");
        }

        return(0);
    }
Example #10
0
        public void SendMessage(string methodName, object value, SendMessageOptions sendMessageOptions)
        {
            bool hadListener = false;

            for (int i = 0; i < components.Count; i++)
            {
                Component cmp = components[i];
                if (!cmp.GetType().IsSubclassOf(typeof(MonoBehaviour)))
                {
                    continue;
                }
                hadListener = cmp.SendMessage(methodName, value);
            }
#if DEBUG
            if (sendMessageOptions == SendMessageOptions.RequireReceiver && !hadListener)
            {
                Debug.Log("There were no listeners to the message " + methodName + " on " + this.ToString());
            }
#endif
        }
Example #11
0
 protected override void Update()
 {
     if (TargetObject != null && !string.IsNullOrEmpty(MethodName))
     {
         SendMessageOptions options = SendMessageOptions.DontRequireReceiver;
         if (IsReceiverRequired)
         {
             options = SendMessageOptions.RequireReceiver;
         }
         if (string.IsNullOrEmpty(DataString))
         {
             TargetObject.SendMessage(MethodName, GetTarget(), options);
         }
         else
         {
             TargetObject.SendMessage(MethodName, DataString, options);
         }
     }
     Completed();
 }
Example #12
0
 public override void Reset()
 {
     gameObject          = new ConcreteGameObjectVar(this.self);
     methodName          = new ConcreteStringVar();
     options             = SendMessageOptions.RequireReceiver;
     floatParameter      = new ConcreteFloatVar();
     intParameter        = new ConcreteIntVar();
     boolParameter       = new ConcreteBoolVar();
     stringParameter     = new ConcreteStringVar();
     vector3Parameter    = new ConcreteVector3Var();
     rectParameter       = new ConcreteRectVar();
     colorParameter      = new ConcreteColorVar();
     quaternionParameter = new ConcreteQuaternionVar();
     gameObjectParameter = new ConcreteGameObjectVar(this.self);
     textureParameter    = new ConcreteTextureVar();
     materialParameter   = new ConcreteMaterialVar();
     fsmEventParameter   = new ConcreteFsmEvent();
     objectParameter     = new ConcreteObjectVar();
     messageType         = MessageType.SendMessage;
 }
Example #13
0
 /// <summary>
 /// Forwards previously sent messages. Returns the forwarded messages in the same order as the message identifiers passed in message_ids. If a message can't be forwarded, null will be returned instead of the message
 /// </summary>
 public static Task <Messages> ForwardMessagesAsync(this Client client,
                                                    long chatId                = default(long),
                                                    long fromChatId            = default(long),
                                                    long[] messageIds          = default(long[]),
                                                    SendMessageOptions options = default(SendMessageOptions),
                                                    bool asAlbum               = default(bool),
                                                    bool sendCopy              = default(bool),
                                                    bool removeCaption         = default(bool))
 {
     return(client.ExecuteAsync(new ForwardMessages
     {
         ChatId = chatId,
         FromChatId = fromChatId,
         MessageIds = messageIds,
         Options = options,
         AsAlbum = asAlbum,
         SendCopy = sendCopy,
         RemoveCaption = removeCaption,
     }));
 }
Example #14
0
    private static int BroadcastMessage(IntPtr L)
    {
        int num = LuaDLL.lua_gettop(L);

        if (num == 2)
        {
            Component component = (Component)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Component");
            string    luaString = LuaScriptMgr.GetLuaString(L, 2);
            component.BroadcastMessage(luaString);
            return(0);
        }
        if (num == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(Component), typeof(string), typeof(SendMessageOptions)))
        {
            Component          component2 = (Component)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Component");
            string             @string    = LuaScriptMgr.GetString(L, 2);
            SendMessageOptions options    = (SendMessageOptions)((int)LuaScriptMgr.GetLuaObject(L, 3));
            component2.BroadcastMessage(@string, options);
            return(0);
        }
        if (num == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(Component), typeof(string), typeof(object)))
        {
            Component component3 = (Component)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Component");
            string    string2    = LuaScriptMgr.GetString(L, 2);
            object    varObject  = LuaScriptMgr.GetVarObject(L, 3);
            component3.BroadcastMessage(string2, varObject);
            return(0);
        }
        if (num == 4)
        {
            Component          component4 = (Component)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Component");
            string             luaString2 = LuaScriptMgr.GetLuaString(L, 2);
            object             varObject2 = LuaScriptMgr.GetVarObject(L, 3);
            SendMessageOptions options2   = (SendMessageOptions)((int)LuaScriptMgr.GetNetObject(L, 4, typeof(SendMessageOptions)));
            component4.BroadcastMessage(luaString2, varObject2, options2);
            return(0);
        }
        LuaDLL.luaL_error(L, "invalid arguments to method: Component.BroadcastMessage");
        return(0);
    }
    private static int SendMessageUpwards(IntPtr L)
    {
        int num = LuaDLL.lua_gettop(L);

        if (num == 2)
        {
            GameObject gameObject = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");
            string     luaString  = LuaScriptMgr.GetLuaString(L, 2);
            gameObject.SendMessageUpwards(luaString);
            return(0);
        }
        if (num == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(GameObject), typeof(string), typeof(SendMessageOptions)))
        {
            GameObject         gameObject2 = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");
            string             @string     = LuaScriptMgr.GetString(L, 2);
            SendMessageOptions options     = (SendMessageOptions)((int)LuaScriptMgr.GetLuaObject(L, 3));
            gameObject2.SendMessageUpwards(@string, options);
            return(0);
        }
        if (num == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(GameObject), typeof(string), typeof(object)))
        {
            GameObject gameObject3 = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");
            string     string2     = LuaScriptMgr.GetString(L, 2);
            object     varObject   = LuaScriptMgr.GetVarObject(L, 3);
            gameObject3.SendMessageUpwards(string2, varObject);
            return(0);
        }
        if (num == 4)
        {
            GameObject         gameObject4 = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");
            string             luaString2  = LuaScriptMgr.GetLuaString(L, 2);
            object             varObject2  = LuaScriptMgr.GetVarObject(L, 3);
            SendMessageOptions options2    = (SendMessageOptions)((int)LuaScriptMgr.GetNetObject(L, 4, typeof(SendMessageOptions)));
            gameObject4.SendMessageUpwards(luaString2, varObject2, options2);
            return(0);
        }
        LuaDLL.luaL_error(L, "invalid arguments to method: GameObject.SendMessageUpwards");
        return(0);
    }
Example #16
0
    private static int SendMessageUpwards(IntPtr L)
    {
        int num = LuaDLL.lua_gettop(L);

        if (num == 2)
        {
            GameObject obj2      = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");
            string     luaString = LuaScriptMgr.GetLuaString(L, 2);
            obj2.SendMessageUpwards(luaString);
            return(0);
        }
        if ((num == 3) && LuaScriptMgr.CheckTypes(L, 1, typeof(GameObject), typeof(string), typeof(SendMessageOptions)))
        {
            GameObject         obj3       = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");
            string             methodName = LuaScriptMgr.GetString(L, 2);
            SendMessageOptions luaObject  = (SendMessageOptions)((int)LuaScriptMgr.GetLuaObject(L, 3));
            obj3.SendMessageUpwards(methodName, luaObject);
            return(0);
        }
        if ((num == 3) && LuaScriptMgr.CheckTypes(L, 1, typeof(GameObject), typeof(string), typeof(object)))
        {
            GameObject obj4      = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");
            string     str3      = LuaScriptMgr.GetString(L, 2);
            object     varObject = LuaScriptMgr.GetVarObject(L, 3);
            obj4.SendMessageUpwards(str3, varObject);
            return(0);
        }
        if (num == 4)
        {
            GameObject         obj6    = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");
            string             str4    = LuaScriptMgr.GetLuaString(L, 2);
            object             obj7    = LuaScriptMgr.GetVarObject(L, 3);
            SendMessageOptions options = (SendMessageOptions)((int)LuaScriptMgr.GetNetObject(L, 4, typeof(SendMessageOptions)));
            obj6.SendMessageUpwards(str4, obj7, options);
            return(0);
        }
        LuaDLL.luaL_error(L, "invalid arguments to method: GameObject.SendMessageUpwards");
        return(0);
    }
    void Notify(string message, GameObject detectedObject)
    {
        SendMessageOptions options = m_RequireReceiver? SendMessageOptions.RequireReceiver : SendMessageOptions.DontRequireReceiver;

        switch (m_NotificationMode)
        {
        case NotificationMode.SELF:
        {
            gameObject.SendMessage(message, detectedObject, options);
            break;
        }

        case NotificationMode.SELF_AND_CHILDREN:
        {
            gameObject.BroadcastMessage(message, detectedObject, options);
            break;
        }

        case NotificationMode.PARENT:
        {
            if (null != transform.parent)
            {
                transform.parent.gameObject.SendMessage(message, detectedObject, options);
            }

            break;
        }

        case NotificationMode.PARENT_AND_SIBLINGS:
        {
            if (null != transform.parent)
            {
                transform.parent.gameObject.BroadcastMessage(message, detectedObject, options);
            }

            break;
        }
        }
    }
        public OperationResult SendMessage(SendMessageOptions sendMessageOptions)
        {
            OperationResult operationResult;

            try
            {
                var domainMessage = mapper.Map <DomainModels.ChatMessage>(sendMessageOptions);
                this.chatService.SendMessage(domainMessage);

                var chatMembers = this.chatService.GetMembersOfChat(sendMessageOptions.ChatId);
                foreach (var member in chatMembers)
                {
                    try
                    {
                        if (this.chatServiceCallbacks.ContainsKey(member.Login))
                        {
                            var userChatServiceCallback = this.chatServiceCallbacks[member.Login];
                            userChatServiceCallback.ReceiveMessage(sendMessageOptions);
                        }
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception);
                    }
                }

                operationResult = new OperationResult(OperationResultTypes.Success);
            }
            catch (Exception exception)
            {
                operationResult = new OperationResult(
                    operationResultType: OperationResultTypes.Failure,
                    message: exception.ToString());
            }

            return(operationResult);
        }
Example #19
0
 protected void SendMessage(string methodName, object value, SendMessageOptions options)
 {
     GameObject.SendMessage(methodName, value, options);
 }
Example #20
0
		public void SendMessage (string message, PauseMessageParameter parameter, SendMessageOptions options)
		{
			
		}
Example #21
0
 public static void SendEvent(this MonoBehaviour comp, String methodName, UnityEventArgs handler, SendMessageOptions options)
 {
     SendEvent((Component)comp, methodName, handler, options);
 }
Example #22
0
 public static CommandDelegate SendMessage(GameObject gm, string eventName, object obj  = null, SendMessageOptions options = SendMessageOptions.DontRequireReceiver)
 {
     return Commands.Do( () => gm.SendMessage (eventName, obj, options));
 }
Example #23
0
 /// <summary>Inserts the given SendMessage callback at the given time position.</summary>
 /// <param name="p_time">Time position where this callback will be placed
 /// (if longer than the whole sequence duration, the callback will never be called)</param>
 /// <param name="p_sendMessageTarget">GameObject to target for sendMessage</param>
 /// <param name="p_methodName">Name of the method to call</param>
 /// <param name="p_value">Eventual additional parameter</param>
 /// <param name="p_options">SendMessageOptions</param>
 public void InsertCallback(float p_time, GameObject p_sendMessageTarget, string p_methodName, object p_value, SendMessageOptions p_options = SendMessageOptions.RequireReceiver)
 {
     TweenDelegate.TweenCallbackWParms cb = HOTween.DoSendMessage;
     object[] cbParms = new[] {
         p_sendMessageTarget,
         p_methodName,
         p_value,
         p_options
     };
     InsertCallback(p_time, null, cb, cbParms);
 }
		public void BroadcastMessage(string methodName, SendMessageOptions options){}
Example #25
0
 /// <summary>
 /// Uses sendMessage to call the method named p_methodName 
 /// on every MonoBehaviour in the p_sendMessageTarget GameObject.
 /// </summary>
 /// <param name="p_sendMessageTarget">GameObject to target for sendMessage</param>
 /// <param name="p_methodName">Name of the method to call</param>
 /// <param name="p_value">Eventual additional parameter</param>
 /// <param name="p_options">SendMessageOptions</param>
 public TweenParms OnComplete(GameObject p_sendMessageTarget, string p_methodName, object p_value = null, SendMessageOptions p_options = SendMessageOptions.RequireReceiver)
 {
     onCompleteWParms = HOTween.DoSendMessage;
     onCompleteParms = new object[4] {
         p_sendMessageTarget,
         p_methodName,
         p_value,
         p_options
     };
     return this;
 }
Example #26
0
 public static void SendMessageToAll(string methodName, object argument, SendMessageOptions options)
 {
     foreach(GameObject go in FindObjectsOfType(typeof(GameObject)))
       go.SendMessage(methodName, argument, options);
 }
Example #27
0
 private void RouteMessage(string messageName, SendMessageOptions sendOptions)
 {
     base.idMain.SendMessage(messageName, sendOptions);
 }
	void DrawBaking () {
		bool pre = showBaking;
		showBaking = EditorGUILayout.Foldout(showBaking, new GUIContent("Baking", SpineEditorUtilities.Icons.unityIcon));
		if (pre != showBaking)
			EditorPrefs.SetBool("SkeletonDataAssetInspector_showBaking", showBaking);

		if (showBaking) {
			EditorGUI.indentLevel++;
			bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations);
			EditorGUI.BeginDisabledGroup(bakeAnimations == false);
			{
				EditorGUI.indentLevel++;
				bakeIK = EditorGUILayout.Toggle("Bake IK", bakeIK);
				bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup("Event Options", bakeEventOptions);
				EditorGUI.indentLevel--;
			}
			EditorGUI.EndDisabledGroup();

			EditorGUI.indentLevel++;
			GUILayout.BeginHorizontal();
			{


				if (GUILayout.Button(new GUIContent("Bake All Skins", SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(150)))
					SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, m_skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions);

				string skinName = "<No Skin>";

				if (m_skeletonAnimation != null && m_skeletonAnimation.skeleton != null) {

					Skin bakeSkin = m_skeletonAnimation.skeleton.Skin;
					if (bakeSkin == null) {
						skinName = "Default";
						bakeSkin = m_skeletonData.Skins[0];
					} else
						skinName = m_skeletonAnimation.skeleton.Skin.Name;

					bool oops = false;

					try {
						GUILayout.BeginVertical();
						if (GUILayout.Button(new GUIContent("Bake " + skinName, SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250)))
							SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new List<Skin>(new Skin[] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);

						GUILayout.BeginHorizontal();
						GUILayout.Label(new GUIContent("Skins", SpineEditorUtilities.Icons.skinsRoot), GUILayout.Width(50));
						if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196))) {
							SelectSkinContext();
						}
						GUILayout.EndHorizontal();



					} catch {
						oops = true;
						//GUILayout.BeginVertical();
					}



					if (!oops)
						GUILayout.EndVertical();
				}

			}
			GUILayout.EndHorizontal();
			EditorGUI.indentLevel--;
			EditorGUI.indentLevel--;
		}


	}
		void DrawUnityTools () {
			#if SPINE_SKELETON_ANIMATOR
			showMecanim = EditorGUILayout.Foldout(showMecanim, new GUIContent("SkeletonAnimator", SpineEditorUtilities.Icons.unityIcon));
			if (showMecanim) {
				EditorGUI.indentLevel++;
				EditorGUILayout.PropertyField(controller, new GUIContent("Controller", SpineEditorUtilities.Icons.controllerIcon));		
				if (controller.objectReferenceValue == null) {
					GUILayout.BeginHorizontal();
					GUILayout.Space(32);
					if (GUILayout.Button(new GUIContent("Generate Mecanim Controller"), GUILayout.Width(195), GUILayout.Height(20)))
						SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);
					GUILayout.EndHorizontal();
					EditorGUILayout.LabelField("SkeletonAnimator is the Mecanim alternative to SkeletonAnimation. It is not required.", EditorStyles.miniLabel);
				} else {
					GUILayout.BeginHorizontal();
					GUILayout.Space(32);
					if (GUILayout.Button(new GUIContent("Update Controller Animations"), GUILayout.Width(195), GUILayout.Height(20)))
						SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);				
					GUILayout.EndHorizontal();
				}
				EditorGUI.indentLevel--;
			}
			#endif

			bool pre = showBaking;
			showBaking = EditorGUILayout.Foldout(showBaking, new GUIContent("Baking", SpineEditorUtilities.Icons.unityIcon));
			if (pre != showBaking)
				EditorPrefs.SetBool("SkeletonDataAssetInspector_showUnity", showBaking);

			if (showBaking) {
				EditorGUI.indentLevel++;
				EditorGUILayout.HelpBox("WARNING!\n\nBaking is NOT the same as SkeletonAnimator!\nDoes not support the following:\n\tFlipX or Y\n\tInheritScale\n\tColor Keys\n\tDraw Order Keys\n\tIK and Curves are sampled at 60fps and are not realtime.\n\tPlease read SkeletonBaker.cs comments for full details.\n\nThe main use of Baking is to export Spine projects to be used without the Spine Runtime (ie: for sale on the Asset Store, or background objects that are animated only with a wind noise generator)", MessageType.Warning, true);
				EditorGUI.indentLevel++;
				bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations);
				EditorGUI.BeginDisabledGroup(!bakeAnimations);
				{
					EditorGUI.indentLevel++;
					bakeIK = EditorGUILayout.Toggle("Bake IK", bakeIK);
					bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup("Event Options", bakeEventOptions);
					EditorGUI.indentLevel--;
				}
				EditorGUI.EndDisabledGroup();

				EditorGUI.indentLevel++;
				using (new EditorGUILayout.HorizontalScope()) {
					if (GUILayout.Button(new GUIContent("Bake All Skins", SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(150)))
						SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, m_skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions);

					string skinName = "<No Skin>";

					if (m_skeletonAnimation != null && m_skeletonAnimation.skeleton != null) {

						Skin bakeSkin = m_skeletonAnimation.skeleton.Skin;
						if (bakeSkin == null) {
							skinName = "Default";
							bakeSkin = m_skeletonData.Skins.Items[0];
						} else
							skinName = m_skeletonAnimation.skeleton.Skin.Name;

						using (var m = new EditorGUILayout.VerticalScope()) {
							if (GUILayout.Button(new GUIContent("Bake " + skinName, SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250)))
								SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new ExposedList<Skin>(new [] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
							using (new EditorGUILayout.HorizontalScope()) {
								GUILayout.Label(new GUIContent("Skins", SpineEditorUtilities.Icons.skinsRoot), GUILayout.Width(50));
								if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196))) {
									SelectSkinContext();
								}
							}

						}
					}

				}
				EditorGUI.indentLevel--;
				EditorGUI.indentLevel--;
			}


		}
		public void SendMessage(string methodName, System.Object value, SendMessageOptions options){}
		public void SendMessage(string methodName, SendMessageOptions options){}
 /// <summary>
 /// Assigns the given callback to this Tweener/Sequence,
 /// overwriting any existing callbacks of the same type.
 /// This overload will use sendMessage to call the method named p_methodName 
 /// on every MonoBehaviour in the p_sendMessageTarget GameObject.
 /// </summary>
 /// <param name="p_callbackType">The type of callback to apply</param>
 /// <param name="p_sendMessageTarget">GameObject to target for sendMessage</param>
 /// <param name="p_methodName">Name of the method to call</param>
 /// <param name="p_value">Eventual additional parameter</param>
 /// <param name="p_options">SendMessageOptions</param>
 public void ApplyCallback(CallbackType p_callbackType, GameObject p_sendMessageTarget, string p_methodName, object p_value, SendMessageOptions p_options = SendMessageOptions.RequireReceiver)
 {
     TweenDelegate.TweenCallbackWParms cb = HOTween.DoSendMessage;
     object[] cbParms = new[] {
         p_sendMessageTarget,
         p_methodName,
         p_value,
         p_options
     };
     ApplyCallback(true, p_callbackType, null, cb, cbParms);
 }
 public Select SendMessage(string message, SendMessageOptions options)
 {
     return(Each(obj => obj.SendMessage(message, options)));
 }
Example #34
0
 public static void BroadcastMessage(Transform transform, string messageName, SendMessageOptions smo)
 {
     BroadcastMessage(transform, messageName, null, smo);
 }
Example #35
0
 public static void SendMessage(Component component, string messageName, SendMessageOptions smo)
 {
     SendMessage(component, messageName, smo);
 }
Example #36
0
 public void  SendMessageTo(GameObject target, string methodName, SendMessageOptions options)
 {
     SendMessageTo(target, methodName, null, options);
 }
Example #37
0
 /// <summary>
 ///   <para></para>
 /// </summary>
 /// <param name="methodName"></param>
 /// <param name="options"></param>
 public void BroadcastMessage(string methodName, SendMessageOptions options)
 {
     this.BroadcastMessage(methodName, (object)null, options);
 }
Example #38
0
 public void  SendMessageTo(GameObject target, string methodName, [DefaultValue("null")] object value, [DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options)
 {
     Debug.Log(string.Format("Sending message '{0}' from {1}({2}) to {3}({4}): {0}, {5}", methodName, this.name, this.GetType().Name, target.name, target.GetType().Name, value));
     target.SendMessage(methodName, value, options);
 }
 public override void Reset()
 {
     gameObject = null;
     options = SendMessageOptions.DontRequireReceiver;
     functionName = "";
 }
 /// <summary>
 /// 在此游戏物体以及它的父级物体的每个 MonoBehavior 上调用指定的名字的方法。
 /// <para>接收消息的方法可以通过定义零个参数来忽略 parameter. 如果 options 设置为 SendMessageOptions.RequireReceiver,那么一旦这条消息没被任何组件拾取,就会打印出错误信息。</para>
 /// <para>请注意,消息不会发送到不活动的物体(例如那些在编辑器中设置为无效化的,或者那些通过 SetActive 函数设置为无效化的)。</para>
 /// </summary>
 /// <param name="methodName">要调用的方法的名字</param>
 /// <param name="value">传递的参数</param>
 /// <param name="options">如果目标物体上不存在指定的方法,是否要报告错误</param>
 public void SendMessageUpwards(string methodName, object value, SendMessageOptions options)
 {
 }
Example #41
0
 /// <summary>Appends the given SendMessage callback to this Sequence.</summary>
 /// <param name="p_sendMessageTarget">GameObject to target for sendMessage</param>
 /// <param name="p_methodName">Name of the method to call</param>
 /// <param name="p_value">Eventual additional parameter</param>
 /// <param name="p_options">SendMessageOptions</param>
 public void AppendCallback(GameObject p_sendMessageTarget, string p_methodName, object p_value, SendMessageOptions p_options = SendMessageOptions.RequireReceiver)
 { InsertCallback(_duration, p_sendMessageTarget, p_methodName, p_value, p_options); }
Example #42
0
	static void ParseEventTimeline (EventTimeline timeline, AnimationClip clip, SendMessageOptions eventOptions) {

		float[] frames = timeline.Frames;
		var events = timeline.Events;

		List<AnimationEvent> animEvents = new List<AnimationEvent>();
		for (int i = 0; i < frames.Length; i++) {
			var ev = events[i];

			AnimationEvent ae = new AnimationEvent();
			//TODO:  Deal with Mecanim's zero-time missed event
			ae.time = frames[i];
			ae.functionName = ev.Data.Name;
			ae.messageOptions = eventOptions;

			if (ev.String != "" && ev.String != null) {
				ae.stringParameter = ev.String;
			} else {
				if (ev.Int == 0 && ev.Float == 0) {
					//do nothing, raw function
				} else {
					if (ev.Int != 0)
						ae.floatParameter = (float)ev.Int;
					else
						ae.floatParameter = ev.Float;
				}

			}

			animEvents.Add(ae);
		}

		AnimationUtility.SetAnimationEvents(clip, animEvents.ToArray());
	}
		void DrawUnityTools () {
			#if SPINE_SKELETON_ANIMATOR
			isMecanimExpanded = EditorGUILayout.Foldout(isMecanimExpanded, new GUIContent("SkeletonAnimator", SpineEditorUtilities.Icons.unityIcon));
			if (isMecanimExpanded) {
				EditorGUI.indentLevel++;
				EditorGUILayout.PropertyField(controller, new GUIContent("Controller", SpineEditorUtilities.Icons.controllerIcon));		
				if (controller.objectReferenceValue == null) {
					
					// Generate Mecanim Controller Button
					using (new GUILayout.HorizontalScope()) {
						GUILayout.Space(EditorGUIUtility.labelWidth);
						if (GUILayout.Button(new GUIContent("Generate Mecanim Controller"), GUILayout.Height(20)))
							SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);						
					}
					EditorGUILayout.HelpBox("SkeletonAnimator is the Mecanim alternative to SkeletonAnimation.\nIt is not required.", MessageType.Info);

				} else {
					
					// Update AnimationClips button.
					using (new GUILayout.HorizontalScope()) {
						GUILayout.Space(EditorGUIUtility.labelWidth);
						if (GUILayout.Button(new GUIContent("Force Update AnimationClips"), GUILayout.Height(20)))
							SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);				
					}

				}
				EditorGUI.indentLevel--;
			}
			#endif

			#if SPINE_BAKING
			bool pre = isBakingExpanded;
			isBakingExpanded = EditorGUILayout.Foldout(isBakingExpanded, new GUIContent("Baking", SpineEditorUtilities.Icons.unityIcon));
			if (pre != isBakingExpanded)
				EditorPrefs.SetBool(ShowBakingPrefsKey, isBakingExpanded);
			
			if (isBakingExpanded) {
				EditorGUI.indentLevel++;
				const string BakingWarningMessage =
					"WARNING!" +
					"\nBaking is NOT the same as SkeletonAnimator!" +

					"\n\nThe main use of Baking is to export Spine projects to be used without the Spine Runtime (ie: for sale on the Asset Store, or background objects that are animated only with a wind noise generator)" +

					"\n\nBaking also does not support the following:" +
					"\n\tDisabled transform inheritance" +
					"\n\tShear" +
					"\n\tColor Keys" +
					"\n\tDraw Order Keys" +
					"\n\tAll Constraint types" +

					"\n\nCurves are sampled at 60fps and are not realtime." +
					"\nPlease read SkeletonBaker.cs comments for full details.";
				EditorGUILayout.HelpBox(BakingWarningMessage, MessageType.Warning, true);

				EditorGUI.indentLevel++;
				bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations);
				using (new EditorGUI.DisabledGroupScope(!bakeAnimations)) {
					EditorGUI.indentLevel++;
					bakeIK = EditorGUILayout.Toggle("Bake IK", bakeIK);
					bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup("Event Options", bakeEventOptions);
					EditorGUI.indentLevel--;
				}

				// Bake Skin buttons.
				using (new GUILayout.HorizontalScope()) {
					if (GUILayout.Button(new GUIContent("Bake All Skins", SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(150)))
						SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, m_skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions);
					
					if (m_skeletonAnimation != null && m_skeletonAnimation.skeleton != null) {
						Skin bakeSkin = m_skeletonAnimation.skeleton.Skin;

						string skinName = "<No Skin>";
						if (bakeSkin == null) {
							skinName = "Default";
							bakeSkin = m_skeletonData.Skins.Items[0];
						} else
							skinName = m_skeletonAnimation.skeleton.Skin.Name;

						using (new GUILayout.VerticalScope()) {
							if (GUILayout.Button(new GUIContent("Bake \"" + skinName + "\"", SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250)))
								SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new ExposedList<Skin>(new [] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
							using (new GUILayout.HorizontalScope()) {
								GUILayout.Label(new GUIContent("Skins", SpineEditorUtilities.Icons.skinsRoot), GUILayout.Width(50));
								if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196))) {
									DrawSkinDropdown();
								}
							}
						}
					}
				}

				EditorGUI.indentLevel--;
				EditorGUI.indentLevel--;
			}
			#endif
		}
 void SendSpawnInfoToGameObject(string msg, GameObject gameObject, NetPlayerState netPlayerState, SendMessageOptions sendMessageOptions = SendMessageOptions.RequireReceiver)
 {
     SpawnInfo spawnInfo = new SpawnInfo();
     spawnInfo.netPlayer = netPlayerState.netPlayer;
     spawnInfo.data = netPlayerState.data;
     gameObject.SendMessage(msg, spawnInfo, sendMessageOptions);
 }
Example #45
0
 public static void SendEvent(this GameObject go, String methodName, UnityEventArgs handler, SendMessageOptions options)
 {
     if (go == null)
     {
         throw new ArgumentNullException("go");
     }
     if (String.IsNullOrEmpty(methodName))
     {
         throw new ArgumentNullException("methodName");
     }
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
     go.SendMessage(methodName, handler, options);
 }
Example #46
0
 public void SendMessage(string methodName, [DefaultValue("null")] object value, [DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options);
Example #47
0
 public static void SendEvent(this Component comp, String methodName, UnityEventArgs handler, SendMessageOptions options)
 {
     if (comp == null)
     {
         throw new ArgumentNullException("comp");
     }
     if (String.IsNullOrEmpty(methodName))
     {
         throw new ArgumentNullException("methodName");
     }
     if (handler == null)
     {
         throw new ArgumentNullException("handler");
     }
     comp.SendMessage(methodName, handler, options);
 }
Example #48
0
        public void SendMessage(string methodName, object value)
        {
            SendMessageOptions options = SendMessageOptions.RequireReceiver;

            this.SendMessage(methodName, value, options);
        }
Example #49
0
        void OnGUI()
        {
            so = so ?? new SerializedObject(this);

            EditorGUIUtility.wideMode = true;
            EditorGUILayout.LabelField("Spine Skeleton Prefab Baking", EditorStyles.boldLabel);

            const string BakingWarningMessage = "\nSkeleton baking is not the primary use case for Spine skeletons." +
                                                "\nUse baking if you have specialized uses, such as simplified skeletons with movement driven by physics." +

                                                "\n\nBaked Skeletons do not support the following:" +
                                                "\n\tDisabled rotation or scale inheritance" +
                                                "\n\tLocal Shear" +
                                                "\n\tAll Constraint types" +
                                                "\n\tWeighted mesh verts with more than 4 bound bones" +

                                                "\n\nBaked Animations do not support the following:" +
                                                "\n\tMesh Deform Keys" +
                                                "\n\tColor Keys" +
                                                "\n\tDraw Order Keys" +

                                                "\n\nAnimation Curves are sampled at 60fps and are not realtime." +
                                                "\nConstraint animations are also baked into animation curves." +
                                                "\nSee SkeletonBaker.cs comments for full details.\n";

            EditorGUILayout.HelpBox(BakingWarningMessage, MessageType.Info, true);

            EditorGUI.BeginChangeCheck();
            var skeletonDataAssetProperty = so.FindProperty("skeletonDataAsset");

            EditorGUILayout.PropertyField(skeletonDataAssetProperty, SpineInspectorUtility.TempContent("SkeletonDataAsset", Icons.spine));
            if (EditorGUI.EndChangeCheck())
            {
                so.ApplyModifiedProperties();
                DataAssetChanged();
            }
            EditorGUILayout.Space();

            if (skeletonDataAsset == null)
            {
                return;
            }
            var skeletonData = skeletonDataAsset.GetSkeletonData(false);

            if (skeletonData == null)
            {
                return;
            }
            bool hasExtraSkins = skeletonData.Skins.Count > 1;

            using (new SpineInspectorUtility.BoxScope(false)) {
                EditorGUILayout.LabelField(skeletonDataAsset.name, EditorStyles.boldLabel);
                using (new SpineInspectorUtility.IndentScope()) {
                    EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Bones: " + skeletonData.Bones.Count, Icons.bone));
                    EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Slots: " + skeletonData.Slots.Count, Icons.slotRoot));

                    if (hasExtraSkins)
                    {
                        EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Skins: " + skeletonData.Skins.Count, Icons.skinsRoot));
                        EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Current skin attachments: " + (bakeSkin == null ? 0 : bakeSkin.Attachments.Count), Icons.skinPlaceholder));
                    }
                    else if (skeletonData.Skins.Count == 1)
                    {
                        EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Skins: 1 (only default Skin)", Icons.skinsRoot));
                    }

                    int totalAttachments = 0;
                    foreach (var s in skeletonData.Skins)
                    {
                        totalAttachments += s.Attachments.Count;
                    }
                    EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Total Attachments: " + totalAttachments, Icons.genericAttachment));
                }
            }
            using (new SpineInspectorUtility.BoxScope(false)) {
                EditorGUILayout.LabelField("Animations", EditorStyles.boldLabel);
                EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Animations: " + skeletonData.Animations.Count, Icons.animation));

                using (new SpineInspectorUtility.IndentScope()) {
                    bakeAnimations = EditorGUILayout.Toggle(SpineInspectorUtility.TempContent("Bake Animations", Icons.animationRoot), bakeAnimations);
                    using (new EditorGUI.DisabledScope(!bakeAnimations)) {
                        using (new SpineInspectorUtility.IndentScope()) {
                            bakeIK           = EditorGUILayout.Toggle(SpineInspectorUtility.TempContent("Bake IK", Icons.constraintIK), bakeIK);
                            bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup(SpineInspectorUtility.TempContent("Event Options", Icons.userEvent), bakeEventOptions);
                        }
                    }
                }
            }
            EditorGUILayout.Space();

            if (!string.IsNullOrEmpty(skinToBake) && UnityEngine.Event.current.type == EventType.Repaint)
            {
                bakeSkin = skeletonData.FindSkin(skinToBake) ?? skeletonData.DefaultSkin;
            }

            var prefabIcon = EditorGUIUtility.FindTexture("PrefabModel Icon");

            if (hasExtraSkins)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(so.FindProperty("skinToBake"));
                if (EditorGUI.EndChangeCheck())
                {
                    so.ApplyModifiedProperties();
                    Repaint();
                }

                if (SpineInspectorUtility.LargeCenteredButton(SpineInspectorUtility.TempContent(string.Format("Bake Skeleton with Skin ({0})", (bakeSkin == null ? "default" : bakeSkin.Name)), prefabIcon)))
                {
                    SkeletonBaker.BakeToPrefab(skeletonDataAsset, new ExposedList <Skin>(new[] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
                }

                if (SpineInspectorUtility.LargeCenteredButton(SpineInspectorUtility.TempContent(string.Format("Bake All ({0} skins)", skeletonData.Skins.Count), prefabIcon)))
                {
                    SkeletonBaker.BakeToPrefab(skeletonDataAsset, skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions);
                }
            }
            else
            {
                if (SpineInspectorUtility.LargeCenteredButton(SpineInspectorUtility.TempContent("Bake Skeleton", prefabIcon)))
                {
                    SkeletonBaker.BakeToPrefab(skeletonDataAsset, new ExposedList <Skin>(new[] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
                }
            }
        }
Example #50
0
 public void BroadcastMessage(string methodName, [DefaultValue("null")] object parameter, [DefaultValue("SendMessageOptions.RequireReceiver")] SendMessageOptions options);
Example #51
0
        /// <summary>
        /// Sends the specified message to all gameobjects recursively.
        /// </summary>
        public static void SendMessageRecursively(this GameObject gameObject, string methodName, object parameter = null, SendMessageOptions sendMessageOptions = SendMessageOptions.DontRequireReceiver)
        {
            foreach (Transform transform in gameObject.transform)
            {
                SendMessageRecursively(transform.gameObject, methodName, parameter, sendMessageOptions);
            }

            if (parameter == null)
            {
                gameObject.SendMessage(methodName, sendMessageOptions);
            }
            else
            {
                gameObject.SendMessage(methodName, parameter, sendMessageOptions);
            }
        }
Example #52
0
        public void BroadcastMessage(string methodName, object parameter)
        {
            SendMessageOptions options = SendMessageOptions.RequireReceiver;

            this.BroadcastMessage(methodName, parameter, options);
        }
Example #53
0
    public static void SendMessage(Component component, string messageName, object o, SendMessageOptions smo)
    {
        if (component != null)
        {
#if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                var cs = component.GetComponents <Component>();

                foreach (var c in cs)
                {
                    var method = c.GetType().GetMethod(messageName, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

                    if (method != null)
                    {
                        if (o != null)
                        {
                            method.Invoke(c, new object[] { method });
                        }
                        else
                        {
                            method.Invoke(c, null);
                        }
                    }
                }

                return;
            }
#endif
            component.SendMessage(messageName, o, smo);
        }
    }
		public void BroadcastMessage(string methodName, System.Object parameter, SendMessageOptions options){}
Example #55
0
    public static void BroadcastMessage(Transform transform, string messageName, object o, SendMessageOptions smo)
    {
        if (transform != null)
        {
            SendMessage(transform, messageName, o, smo);

            for (var i = transform.childCount - 1; i >= 0; i--)
            {
                BroadcastMessage(transform.GetChild(i), messageName, o, smo);
            }
        }
    }
	void DrawUnityTools () {
		bool pre = showUnity;
		showUnity = EditorGUILayout.Foldout(showUnity, new GUIContent("Unity Tools", SpineEditorUtilities.Icons.unityIcon));
		if (pre != showUnity)
			EditorPrefs.SetBool("SkeletonDataAssetInspector_showUnity", showUnity);

		if (showUnity) {
			EditorGUI.indentLevel++;
			EditorGUILayout.LabelField("SkeletonAnimator", EditorStyles.boldLabel);
			EditorGUI.indentLevel++;
			DrawMecanim();
			EditorGUI.indentLevel--;
			GUILayout.Space(32);
			EditorGUILayout.LabelField("Baking", EditorStyles.boldLabel);
			EditorGUILayout.HelpBox("WARNING!\n\nBaking is NOT the same as SkeletonAnimator!\nDoes not support the following:\n\tFlipX or Y\n\tInheritScale\n\tColor Keys\n\tDraw Order Keys\n\tIK and Curves are sampled at 60fps and are not realtime.\n\tPlease read SkeletonBaker.cs comments for full details.\n\nThe main use of Baking is to export Spine projects to be used without the Spine Runtime (ie: for sale on the Asset Store, or background objects that are animated only with a wind noise generator)", MessageType.Warning, true);
			EditorGUI.indentLevel++;
			bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations);
			EditorGUI.BeginDisabledGroup(bakeAnimations == false);
			{
				EditorGUI.indentLevel++;
				bakeIK = EditorGUILayout.Toggle("Bake IK", bakeIK);
				bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup("Event Options", bakeEventOptions);
				EditorGUI.indentLevel--;
			}
			EditorGUI.EndDisabledGroup();

			EditorGUI.indentLevel++;
			GUILayout.BeginHorizontal();
			{


				if (GUILayout.Button(new GUIContent("Bake All Skins", SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(150)))
					SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, m_skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions);

				string skinName = "<No Skin>";

				if (m_skeletonAnimation != null && m_skeletonAnimation.skeleton != null) {

					Skin bakeSkin = m_skeletonAnimation.skeleton.Skin;
					if (bakeSkin == null) {
						skinName = "Default";
						bakeSkin = m_skeletonData.Skins[0];
					} else
						skinName = m_skeletonAnimation.skeleton.Skin.Name;

					bool oops = false;

					try {
						GUILayout.BeginVertical();
						if (GUILayout.Button(new GUIContent("Bake " + skinName, SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250)))
							SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new List<Skin>(new Skin[] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);

						GUILayout.BeginHorizontal();
						GUILayout.Label(new GUIContent("Skins", SpineEditorUtilities.Icons.skinsRoot), GUILayout.Width(50));
						if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196))) {
							SelectSkinContext();
						}
						GUILayout.EndHorizontal();



					} catch {
						oops = true;
						//GUILayout.BeginVertical();
					}



					if (!oops)
						GUILayout.EndVertical();
				}

			}
			GUILayout.EndHorizontal();
			EditorGUI.indentLevel--;
			EditorGUI.indentLevel--;
		}


	}
Example #57
0
    public void  SendMessageTo(GameObject target, string methodName, object value)
    {
        SendMessageOptions options = SendMessageOptions.RequireReceiver;

        SendMessageTo(target, methodName, value, options);
    }
Example #58
0
	public static void BakeToPrefab (SkeletonDataAsset skeletonDataAsset, List<Skin> skins, string outputPath = "", bool bakeAnimations = true, bool bakeIK = true, SendMessageOptions eventOptions = SendMessageOptions.DontRequireReceiver) {
		if (skeletonDataAsset == null || skeletonDataAsset.GetSkeletonData(true) == null) {
			Debug.LogError("Could not export Spine Skeleton because SkeletonDataAsset is null or invalid!");
			return;
		}

		if (outputPath == "") {
			outputPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(skeletonDataAsset)) + "/Baked";
			System.IO.Directory.CreateDirectory(outputPath);
		}

		var skeletonData = skeletonDataAsset.GetSkeletonData(true);
		bool hasAnimations = bakeAnimations && skeletonData.Animations.Count > 0;
#if UNITY_5
		UnityEditor.Animations.AnimatorController controller = null;
#else
		UnityEditorInternal.AnimatorController controller = null;
#endif
		if (hasAnimations) {
			string controllerPath = outputPath + "/" + skeletonDataAsset.skeletonJSON.name + " Controller.controller";
			bool newAnimContainer = false;

			var runtimeController = AssetDatabase.LoadAssetAtPath(controllerPath, typeof(RuntimeAnimatorController));

#if UNITY_5
			if (runtimeController != null) {
				controller = (UnityEditor.Animations.AnimatorController)runtimeController;
			} else {
				controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
				newAnimContainer = true;
			}
#else
			if (runtimeController != null) {
				controller = (UnityEditorInternal.AnimatorController)runtimeController;
			} else {
				controller = UnityEditorInternal.AnimatorController.CreateAnimatorControllerAtPath(controllerPath);
				newAnimContainer = true;
			}
#endif

			Dictionary<string, AnimationClip> existingClipTable = new Dictionary<string, AnimationClip>();
			List<string> unusedClipNames = new List<string>();
			Object[] animObjs = AssetDatabase.LoadAllAssetsAtPath(controllerPath);

			foreach (Object o in animObjs) {
				if (o is AnimationClip) {
					var clip = (AnimationClip)o;
					existingClipTable.Add(clip.name, clip);
					unusedClipNames.Add(clip.name);
				}
			}

			Dictionary<int, List<string>> slotLookup = new Dictionary<int, List<string>>();

			int skinCount = skins.Count;

			for (int s = 0; s < skeletonData.Slots.Count; s++) {
				List<string> attachmentNames = new List<string>();
				for (int i = 0; i < skinCount; i++) {
					var skin = skins[i];
					List<string> temp = new List<string>();
					skin.FindNamesForSlot(s, temp);
					foreach (string str in temp) {
						if (!attachmentNames.Contains(str))
							attachmentNames.Add(str);
					}
				}
				slotLookup.Add(s, attachmentNames);
			}

			foreach (var anim in skeletonData.Animations) {

				AnimationClip clip = null;
				if (existingClipTable.ContainsKey(anim.Name)) {
					clip = existingClipTable[anim.Name];
				}

				clip = ExtractAnimation(anim.Name, skeletonData, slotLookup, bakeIK, eventOptions, clip);

				if (unusedClipNames.Contains(clip.name)) {
					unusedClipNames.Remove(clip.name);
				} else {
					AssetDatabase.AddObjectToAsset(clip, controller);
#if UNITY_5
					controller.AddMotion(clip);
#else
					UnityEditorInternal.AnimatorController.AddAnimationClipToController(controller, clip);
#endif

				}
			}

			if (newAnimContainer) {
				EditorUtility.SetDirty(controller);
				AssetDatabase.SaveAssets();
				AssetDatabase.ImportAsset(controllerPath, ImportAssetOptions.ForceUpdate);
				AssetDatabase.Refresh();
			} else {

				foreach (string str in unusedClipNames) {
					AnimationClip.DestroyImmediate(existingClipTable[str], true);
				}

				EditorUtility.SetDirty(controller);
				AssetDatabase.SaveAssets();
				AssetDatabase.ImportAsset(controllerPath, ImportAssetOptions.ForceUpdate);
				AssetDatabase.Refresh();
			}
		}

		foreach (var skin in skins) {
			bool newPrefab = false;

			string prefabPath = outputPath + "/" + skeletonDataAsset.skeletonJSON.name + " (" + skin.Name + ").prefab";


			Object prefab = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject));
			if (prefab == null) {
				prefab = PrefabUtility.CreateEmptyPrefab(prefabPath);
				newPrefab = true;
			}

			Dictionary<string, Mesh> meshTable = new Dictionary<string, Mesh>();
			List<string> unusedMeshNames = new List<string>();
			Object[] assets = AssetDatabase.LoadAllAssetsAtPath(prefabPath);
			foreach (var obj in assets) {
				if (obj is Mesh) {
					meshTable.Add(obj.name, (Mesh)obj);
					unusedMeshNames.Add(obj.name);
				}
			}

			GameObject prefabRoot = new GameObject("root");

			Dictionary<string, Transform> slotTable = new Dictionary<string, Transform>();
			Dictionary<string, Transform> boneTable = new Dictionary<string, Transform>();
			List<Transform> boneList = new List<Transform>();

			//create bones
			for (int i = 0; i < skeletonData.Bones.Count; i++) {
				var boneData = skeletonData.Bones[i];
				Transform boneTransform = new GameObject(boneData.Name).transform;
				boneTransform.parent = prefabRoot.transform;
				boneTable.Add(boneTransform.name, boneTransform);
				boneList.Add(boneTransform);
			}

			for (int i = 0; i < skeletonData.Bones.Count; i++) {

				var boneData = skeletonData.Bones[i];
				Transform boneTransform = boneTable[boneData.Name];
				Transform parentTransform = null;
				if (i > 0)
					parentTransform = boneTable[boneData.Parent.Name];
				else
					parentTransform = boneTransform.parent;

				boneTransform.parent = parentTransform;
				boneTransform.localPosition = new Vector3(boneData.X, boneData.Y, 0);
				if (boneData.InheritRotation)
					boneTransform.localRotation = Quaternion.Euler(0, 0, boneData.Rotation);
				else
					boneTransform.rotation = Quaternion.Euler(0, 0, boneData.Rotation);

				if (boneData.InheritScale)
					boneTransform.localScale = new Vector3(boneData.ScaleX, boneData.ScaleY, 1);
			}

			//create slots and attachments
			for (int i = 0; i < skeletonData.Slots.Count; i++) {
				var slotData = skeletonData.Slots[i];
				Transform slotTransform = new GameObject(slotData.Name).transform;
				slotTransform.parent = prefabRoot.transform;
				slotTable.Add(slotData.Name, slotTransform);

				List<Attachment> attachments = new List<Attachment>();
				List<string> attachmentNames = new List<string>();

				skin.FindAttachmentsForSlot(i, attachments);
				skin.FindNamesForSlot(i, attachmentNames);

				if (skin != skeletonData.DefaultSkin) {
					skeletonData.DefaultSkin.FindAttachmentsForSlot(i, attachments);
					skeletonData.DefaultSkin.FindNamesForSlot(i, attachmentNames);
				}

				for (int a = 0; a < attachments.Count; a++) {
					var attachment = attachments[a];
					var attachmentName = attachmentNames[a];
					var attachmentMeshName = "[" + slotData.Name + "] " + attachmentName;
					Vector3 offset = Vector3.zero;
					float rotation = 0;
					Mesh mesh = null;
					Material material = null;

					if (meshTable.ContainsKey(attachmentMeshName))
						mesh = meshTable[attachmentMeshName];
					if (attachment is RegionAttachment) {
						var regionAttachment = (RegionAttachment)attachment;
						offset.x = regionAttachment.X;
						offset.y = regionAttachment.Y;
						rotation = regionAttachment.Rotation;
						mesh = ExtractRegionAttachment(attachmentMeshName, regionAttachment, mesh);
						material = ExtractMaterial((RegionAttachment)attachment);
						unusedMeshNames.Remove(attachmentMeshName);
						if (newPrefab || meshTable.ContainsKey(attachmentMeshName) == false)
							AssetDatabase.AddObjectToAsset(mesh, prefab);
					} else if (attachment is MeshAttachment) {
						var meshAttachment = (MeshAttachment)attachment;
						offset.x = 0;
						offset.y = 0;
						rotation = 0;
						mesh = ExtractMeshAttachment(attachmentMeshName, meshAttachment, mesh);
						material = ExtractMaterial((MeshAttachment)attachment);
						unusedMeshNames.Remove(attachmentMeshName);
						if (newPrefab || meshTable.ContainsKey(attachmentMeshName) == false)
							AssetDatabase.AddObjectToAsset(mesh, prefab);
					} else if (attachment is SkinnedMeshAttachment) {
						var meshAttachment = (SkinnedMeshAttachment)attachment;
						offset.x = 0;
						offset.y = 0;
						rotation = 0;
						mesh = ExtractSkinnedMeshAttachment(attachmentMeshName, meshAttachment, i, skeletonData, boneList, mesh);
						material = ExtractMaterial((SkinnedMeshAttachment)attachment);
						unusedMeshNames.Remove(attachmentMeshName);
						if (newPrefab || meshTable.ContainsKey(attachmentMeshName) == false)
							AssetDatabase.AddObjectToAsset(mesh, prefab);
					} else
						continue;  //disregard unsupported types for now

					Transform attachmentTransform = new GameObject(attachmentName).transform;

					attachmentTransform.parent = slotTransform;
					attachmentTransform.localPosition = offset;
					attachmentTransform.localRotation = Quaternion.Euler(0, 0, rotation);

					if (attachment is SkinnedMeshAttachment) {
						attachmentTransform.position = Vector3.zero;
						attachmentTransform.rotation = Quaternion.identity;
						var skinnedMeshRenderer = attachmentTransform.gameObject.AddComponent<SkinnedMeshRenderer>();
						skinnedMeshRenderer.rootBone = boneList[0];
						skinnedMeshRenderer.bones = boneList.ToArray();
						skinnedMeshRenderer.sharedMesh = mesh;

					} else {
						attachmentTransform.gameObject.AddComponent<MeshFilter>().sharedMesh = mesh;
						attachmentTransform.gameObject.AddComponent<MeshRenderer>();
					}

					attachmentTransform.GetComponent<Renderer>().sharedMaterial = material;
					attachmentTransform.GetComponent<Renderer>().sortingOrder = i;

					if (attachmentName != slotData.AttachmentName)
						attachmentTransform.gameObject.SetActive(false);
				}

			}

			foreach (var slotData in skeletonData.Slots) {
				Transform slotTransform = slotTable[slotData.Name];
				slotTransform.parent = boneTable[slotData.BoneData.Name];
				slotTransform.localPosition = Vector3.zero;
				slotTransform.localRotation = Quaternion.identity;
				slotTransform.localScale = Vector3.one;
			}

			if (hasAnimations) {
				var animator = prefabRoot.AddComponent<Animator>();
				animator.applyRootMotion = false;
				animator.runtimeAnimatorController = (RuntimeAnimatorController)controller;
				EditorGUIUtility.PingObject(controller);
			}


			if (newPrefab) {
				PrefabUtility.ReplacePrefab(prefabRoot, prefab, ReplacePrefabOptions.ConnectToPrefab);
			} else {

				foreach (string str in unusedMeshNames) {
					Mesh.DestroyImmediate(meshTable[str], true);
				}

				PrefabUtility.ReplacePrefab(prefabRoot, prefab, ReplacePrefabOptions.ReplaceNameBased);
			}

			EditorGUIUtility.PingObject(prefab);

			AssetDatabase.Refresh();
			AssetDatabase.SaveAssets();

			GameObject.DestroyImmediate(prefabRoot);
		}

	}
        void DrawUnityTools()
        {
                        #if SPINE_SKELETON_ANIMATOR
            using (new SpineInspectorUtility.BoxScope()) {
                isMecanimExpanded = EditorGUILayout.Foldout(isMecanimExpanded, new GUIContent("SkeletonAnimator", Icons.unityIcon));
                if (isMecanimExpanded)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(controller, new GUIContent("Controller", Icons.controllerIcon));
                    if (controller.objectReferenceValue == null)
                    {
                        // Generate Mecanim Controller Button
                        using (new GUILayout.HorizontalScope()) {
                            GUILayout.Space(EditorGUIUtility.labelWidth);
                            if (GUILayout.Button(new GUIContent("Generate Mecanim Controller"), GUILayout.Height(20)))
                            {
                                SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);
                            }
                        }
                        EditorGUILayout.HelpBox("SkeletonAnimator is the Mecanim alternative to SkeletonAnimation.\nIt is not required.", MessageType.Info);
                    }
                    else
                    {
                        // Update AnimationClips button.
                        using (new GUILayout.HorizontalScope()) {
                            GUILayout.Space(EditorGUIUtility.labelWidth);
                            if (GUILayout.Button(new GUIContent("Force Update AnimationClips"), GUILayout.Height(20)))
                            {
                                SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset);
                            }
                        }
                    }
                    EditorGUI.indentLevel--;
                }
            }
                        #endif

                        #if SPINE_BAKING
            bool pre = isBakingExpanded;
            isBakingExpanded = EditorGUILayout.Foldout(isBakingExpanded, new GUIContent("Baking", Icons.unityIcon));
            if (pre != isBakingExpanded)
            {
                EditorPrefs.SetBool(ShowBakingPrefsKey, isBakingExpanded);
            }

            if (isBakingExpanded)
            {
                EditorGUI.indentLevel++;
                const string BakingWarningMessage =
//					"WARNING!" +
//					"\nBaking is NOT the same as SkeletonAnimator!" +
//					"\n\n" +
                    "The main use of Baking is to export Spine projects to be used without the Spine Runtime (ie: for sale on the Asset Store, or background objects that are animated only with a wind noise generator)" +

                    "\n\nBaking does not support the following:" +
                    "\n\tDisabled transform inheritance" +
                    "\n\tShear" +
                    "\n\tColor Keys" +
                    "\n\tDraw Order Keys" +
                    "\n\tAll Constraint types" +

                    "\n\nCurves are sampled at 60fps and are not realtime." +
                    "\nPlease read SkeletonBaker.cs comments for full details.";
                EditorGUILayout.HelpBox(BakingWarningMessage, MessageType.Info, true);

                EditorGUI.indentLevel++;
                bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations);
                using (new EditorGUI.DisabledGroupScope(!bakeAnimations)) {
                    EditorGUI.indentLevel++;
                    bakeIK           = EditorGUILayout.Toggle("Bake IK", bakeIK);
                    bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup("Event Options", bakeEventOptions);
                    EditorGUI.indentLevel--;
                }

                // Bake Skin buttons.
                using (new GUILayout.HorizontalScope()) {
                    if (GUILayout.Button(new GUIContent("Bake All Skins", Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(150)))
                    {
                        SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, m_skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions);
                    }

                    if (m_skeletonAnimation != null && m_skeletonAnimation.skeleton != null)
                    {
                        Skin bakeSkin = m_skeletonAnimation.skeleton.Skin;

                        string skinName = "<No Skin>";
                        if (bakeSkin == null)
                        {
                            skinName = "Default";
                            bakeSkin = m_skeletonData.Skins.Items[0];
                        }
                        else
                        {
                            skinName = m_skeletonAnimation.skeleton.Skin.Name;
                        }

                        using (new GUILayout.VerticalScope()) {
                            if (GUILayout.Button(new GUIContent("Bake \"" + skinName + "\"", Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250)))
                            {
                                SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new ExposedList <Skin>(new [] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
                            }
                            using (new GUILayout.HorizontalScope()) {
                                GUILayout.Label(new GUIContent("Skins", Icons.skinsRoot), GUILayout.Width(50));
                                if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196)))
                                {
                                    DrawSkinDropdown();
                                }
                            }
                        }
                    }
                }

                EditorGUI.indentLevel--;
                EditorGUI.indentLevel--;
            }
                        #endif
        }
Example #60
0
	static AnimationClip ExtractAnimation (string name, SkeletonData skeletonData, Dictionary<int, List<string>> slotLookup, bool bakeIK, SendMessageOptions eventOptions, AnimationClip clip = null) {
		var animation = skeletonData.FindAnimation(name);

		var timelines = animation.Timelines;

		if (clip == null) {
			clip = new AnimationClip();
		} else {
			clip.ClearCurves();
			AnimationUtility.SetAnimationEvents(clip, new AnimationEvent[0]);
		}

#if UNITY_5

#else
		AnimationUtility.SetAnimationType(clip, ModelImporterAnimationType.Generic);
#endif

		clip.name = name;

		Skeleton skeleton = new Skeleton(skeletonData);

		List<int> ignoreRotateTimelineIndexes = new List<int>();

		if (bakeIK) {
			foreach (IkConstraint i in skeleton.IkConstraints) {
				foreach (Bone b in i.Bones) {
					int index = skeleton.FindBoneIndex(b.Data.Name);
					ignoreRotateTimelineIndexes.Add(index);
					BakeBone(b, animation, clip);
				}
			}
		}

		foreach (Bone b in skeleton.Bones) {
			if (b.Data.InheritRotation == false) {
				int index = skeleton.FindBoneIndex(b.Data.Name);

				if (ignoreRotateTimelineIndexes.Contains(index) == false) {
					ignoreRotateTimelineIndexes.Add(index);
					BakeBone(b, animation, clip);
				}
			}
		}

		foreach (Timeline t in timelines) {
			skeleton.SetToSetupPose();

			if (t is ScaleTimeline) {
				ParseScaleTimeline(skeleton, (ScaleTimeline)t, clip);
			} else if (t is TranslateTimeline) {
				ParseTranslateTimeline(skeleton, (TranslateTimeline)t, clip);
			} else if (t is RotateTimeline) {
				//bypass any rotation keys if they're going to get baked anyway to prevent localEulerAngles vs Baked collision
				if (ignoreRotateTimelineIndexes.Contains(((RotateTimeline)t).BoneIndex) == false)
					ParseRotateTimeline(skeleton, (RotateTimeline)t, clip);
			} else if (t is AttachmentTimeline) {
				ParseAttachmentTimeline(skeleton, (AttachmentTimeline)t, slotLookup, clip);
			} else if (t is EventTimeline) {
				ParseEventTimeline((EventTimeline)t, clip, eventOptions);
			}

		}

		var settings = AnimationUtility.GetAnimationClipSettings(clip);
		settings.loopTime = true;
		settings.stopTime = Mathf.Max(clip.length, 0.001f);

		SetAnimationSettings(clip, settings);

		clip.EnsureQuaternionContinuity();

		EditorUtility.SetDirty(clip);

		return clip;
	}