public override void OnAwake()
        {
            // Find the correct iCodeBehavior based on the name.
            var iCodeBehaviorComponents = targetGameObject != null?targetGameObject.Value.GetComponents <ICodeBehaviour>() : gameObject.GetComponents <ICodeBehaviour>();

            if (iCodeBehaviorComponents != null && iCodeBehaviorComponents.Length > 0)
            {
                iCodeBehavior = iCodeBehaviorComponents[0];
                //  We don't need the group if there is only one State Machine Behaviour component
                if (iCodeBehaviorComponents.Length > 1)
                {
                    for (int i = 0; i < iCodeBehaviorComponents.Length; ++i)
                    {
                        if (iCodeBehaviorComponents[i].group == group.Value)
                        {
                            // Cache the result when we have a match and stop looping.
                            iCodeBehavior = iCodeBehaviorComponents[i];
                            break;
                        }
                    }
                }
            }

            // We can't do much if there isn't a ICodeBehaviour.
            if (iCodeBehavior == null)
            {
                Debug.LogError(string.Format("Unable to find State Machine Behaviour with group {0}{1}", group, (targetGameObject.Value != null ? string.Format(" attached to {0}", targetGameObject.Value.name) : "")));
            }
        }
Ejemplo n.º 2
0
    void Awake()
    {
        animator    = GetComponent <Animator>();
        Icodescript = this.GetComponent <ICodeBehaviour>();

        if (this.gameObject.GetComponent <AudioSource>() == null)
        {
            this.gameObject.AddComponent <AudioSource>();
        }
        sound = this.gameObject.GetComponent <AudioSource>();

        if (berry1 == null && berryPrefab != null)
        {
            int rand = Random.Range(1, 4);
            berry1 = Instantiate(berryPrefab, null);
            rb1    = berry1.transform.GetChild(0).GetComponent <Rigidbody> ();
            berry1.SetActive(false);
            if (rand > 1)
            {
                berry2 = Instantiate(berryPrefab, null);
                rb2    = berry2.transform.GetChild(0).GetComponent <Rigidbody> ();
                berry2.SetActive(false);
            }
            if (rand > 2)
            {
                berry3 = Instantiate(berryPrefab, null);
                rb3    = berry3.transform.GetChild(0).GetComponent <Rigidbody> ();
                berry3.SetActive(false);
            }
        }
    }
Ejemplo n.º 3
0
	private void AddItems(){
		container = GetContainer ();

		if (container != null) {
			if (clearContainer) {
				container.Clear ();
			}

			if (execute != null) {
				if(behaviour == null){
					behaviour = gameObject.AddBehaviour(execute);
					behaviour.stateMachine.SetVariable ("Items", items);
					behaviour.stateMachine.SetVariable ("Container", container.gameObject);
				}
				return;
			}

			for (int i=0; i< items.Length; i++) {
				if (items [i] != null) {
					container.Add (items[i]);
				}
			}

			if(openContainer){
				OpenContainer();
			}
		}
	}
Ejemplo n.º 4
0
		private void OnPlayModeStateChanged(){
			if (ActiveGameObject != null) {
				ICodeBehaviour behaviour=ActiveGameObject.GetComponent<ICodeBehaviour>();
				if(behaviour != null){
					SelectStateMachine(behaviour.stateMachine);
				}
			}	
		}
Ejemplo n.º 5
0
    public void SetTeam(TeamType _Team, GameObject go_hpBar)
    {
        _icode = gameObject.GetBehaviour();
        Team   = _Team;

        _buffManager = this.GetOrAddComponent <BuffManagerScript>();
        SetHpBar(go_hpBar);
    }
        private void OnReceive(NetworkMessage message)
        {
            FsmVariableMessage mMessage = new FsmVariableMessage(null);

            message.ReadMessage <FsmVariableMessage>(mMessage);
            if (execute != null)
            {
                GameObject     go        = new GameObject("Handler");
                ICodeBehaviour behaviour = go.AddBehaviour(execute);
                behaviour.stateMachine.SetVariable("Info", mMessage.variable.GetValue());
            }
        }
Ejemplo n.º 7
0
		public static void SelectGameObject(GameObject gameObject){
			if (FsmEditor.instance == null){ //|| FsmEditor.ActiveGameObject == gameObject) {
				return;			
			}

			if (!PreferencesEditor.GetBool(Preference.LockSelection) && gameObject != null) {
				ICodeBehaviour behaviour = gameObject.GetComponent<ICodeBehaviour> ();
				if(behaviour !=  null && behaviour.stateMachine != null){
					FsmEditor.instance.activeGameObject=behaviour.gameObject;
					FsmEditor.SelectStateMachine(behaviour.stateMachine);
				}	
			}
		}
Ejemplo n.º 8
0
        public override void OnEnter()
        {
            ICodeBehaviour behaviour = gameObject.Value.GetBehaviour(group.Value);

            if (behaviour != null)
            {
                mVaraible = behaviour.stateMachine.GetVariable(variable.Value);
                if (mVaraible != null)
                {
                    mVaraible.SetValue(_value.GetValue());
                }
            }
            Finish();
        }
Ejemplo n.º 9
0
        static void HierarchyWindowItemCallback(int pID, Rect pRect)
        {
            GameObject go = EditorUtility.InstanceIDToObject(pID) as GameObject;

            if (go != null && go.GetComponent <ICodeBehaviour>() != null)
            {
                Rect rect = new Rect(pRect.x + pRect.width - 25, pRect.y - 3, 25, 25);
                GUI.DrawTexture(rect, FsmEditorStyles.iCodeLogo);
                ICodeBehaviour[] behaviours = go.GetComponents <ICodeBehaviour>();
                for (int i = 0; i < behaviours.Length; i++)
                {
                    ICodeBehaviour behaviour = behaviours[i];
                    ErrorChecker.CheckForErrors(behaviour.stateMachine);
                    if (ErrorChecker.HasErrors(behaviour.stateMachine) || behaviour.stateMachine == null)
                    {
                        Rect rect1 = new Rect(pRect.x + pRect.width - 25 - rect.width, pRect.y - 3, 25, 25);
                        GUI.DrawTexture(rect1, EditorGUIUtility.FindTexture("d_console.erroricon"));
                    }
                }
            }

            Event ev = Event.current;

            if (ev.type == EventType.DragPerform)
            {
                DragAndDrop.AcceptDrag();
                var selectedObjects = new List <GameObject>();
                foreach (var objectRef in DragAndDrop.objectReferences)
                {
                    if (objectRef is StateMachine)
                    {
                        if (pRect.Contains(ev.mousePosition))
                        {
                            var gameObject = (GameObject)EditorUtility.InstanceIDToObject(pID);
                            var componentX = gameObject.AddComponent <ICodeBehaviour>();
                            componentX.stateMachine = objectRef as StateMachine;
                            selectedObjects.Add(gameObject);
                        }
                    }
                }

                if (selectedObjects.Count == 0)
                {
                    return;
                }
                Selection.objects = selectedObjects.ToArray();
                ev.Use();
            }
        }
Ejemplo n.º 10
0
        public override void OnEnter()
        {
            ICodeBehaviour behaviour = gameObject.Value.GetBehaviour(group.Value);

            if (behaviour != null)
            {
                mVaraible = behaviour.stateMachine.GetVariable(variable.Value);
                if (mVaraible != null)
                {
                    mVaraible.onVariableChange.AddListener(DoSync);
                }
            }

            Finish();
        }
Ejemplo n.º 11
0
		static void DrawGameObjectName(Transform transform, GizmoType gizmoType)
		{   
			ICodeBehaviour behaviour = transform.GetComponent<ICodeBehaviour> ();
			if (behaviour == null) {
				return;
			}
			if (behaviour.showSceneIcon) {
				Handles.Label (transform.position, FsmEditorStyles.iCodeLogo);
			}
			if ( behaviour.showStateGizmos && behaviour.stateMachine!= null ) { 
				Node activeNode=behaviour.ActiveNode;
				if(activeNode != null){
					Handles.Label (transform.position, activeNode.Name,FsmEditorStyles.stateLabelGizmo);
				}
			}
		}
Ejemplo n.º 12
0
        public static void ICodeFinished(this BehaviorManager behaviorManager, ICodeBehaviour iCodeBehavior, TaskStatus status)
        {
            if (behaviorManager == null)
            {
                return;
            }

            var task = behaviorManager.TaskForObject(iCodeBehavior);

            if (task is Tasks.ICode.StartStateMachine)
            {
                var iCodeTask = task as Tasks.ICode.StartStateMachine;
                iCodeTask.ICodeFinished(status);
            }
            else if (task is RunConditionalStateMachine)
            {
                var iCodeTask = task as RunConditionalStateMachine;
                iCodeTask.ICodeFinished(status);
            }
        }
Ejemplo n.º 13
0
    // Use this for initialization

    //  Spine.TrackEntry

    void Start()
    {
        //mSkeletonAnimation = gameObject.GetComponent<SkeletonAnimation> ();
        //mSkeletonAnimation.AnimationName = walkName;
        mAnimationState = mSkeletonAnimation.state;
        mAnimationState.SetAnimation(0, blinkName, true);

        cb = gameObject.GetBehaviour(0);

        Debug.Log("cb is " + cb);
        // cb.stateMachine.

        FsmVariable move = cb.stateMachine.GetVariable("state");

        move.onVariableChange.AddListener(onFsmStateChange);

        moveTartget = new Vector3(direction == 1 ? pointRight.position.x : pointLeft.position.x, transform.position.y, transform.position.z);

        meshRender = GetComponent <MeshRenderer> ();
    }
Ejemplo n.º 14
0
    void Start()
    {
        initHealth = health;

        if (anim == null && this.gameObject.GetComponent <Animator>() != null)
        {
            anim = this.gameObject.GetComponent <Animator>();
        }
        if (anim != null)
        {
            foreach (AnimatorControllerParameter pa in anim.parameters)
            {
                if (pa.name == "Hurt")
                {
                    hasParam = true;
                }
            }
        }

        if (this.gameObject.GetComponent <Rigidbody>())
        {
            rb = this.gameObject.GetComponent <Rigidbody>();
        }

        if (this.gameObject.GetComponent <BoxCollider>() != null)
        {
            boxCol = this.gameObject.GetComponent <BoxCollider>();
        }
        if (this.gameObject.GetComponent <SphereCollider>() != null)
        {
            sphereCol = this.gameObject.GetComponent <SphereCollider>();
        }

        if (renderers.Length == 0)
        {
            renderers = this.gameObject.GetComponentsInChildren <Renderer>();
        }
        foreach (Renderer r in renderers)
        {
            foreach (Material m in r.materials)
            {
                if (m.HasProperty("_RimColor") && m.HasProperty("_RimIntensityF"))
                {
                    origRimCol.Add(m.GetColor("_RimColor"));
                    origRimInt.Add(m.GetFloat("_RimIntensityF"));
                }
            }
        }

        if (this.GetComponent <ICodeBehaviour>() != null)
        {
            icodescript = this.GetComponent <ICodeBehaviour>();
        }

        if (!damageOnly)
        {
            if (this.transform.parent.parent != null && this.transform.parent.parent.GetComponent <IActivablePrefab>() != null)
            {
                sound = this.transform.parent.parent.gameObject.AddComponent <AudioSource>();
            }
            else
            {
                sound = this.transform.parent.gameObject.AddComponent <AudioSource>();
            }
            sound.playOnAwake = false;
        }

        if (infiniteHealth || damageOnly)
        {
            endCol = new Color(1f, 1f, 1f, 0f);
        }

        if (collidersToIgnore.Length > 0)
        {
            foreach (Collider c in collidersToIgnore)
            {
                if (sphereCol != null)
                {
                    Physics.IgnoreCollision(sphereCol, c, true);
                }
                if (boxCol != null)
                {
                    Physics.IgnoreCollision(boxCol, c, true);
                }
            }
        }

        if (infiniteHealth && instantKill && damageOnly)
        {
            this.enabled = false;
        }
    }
Ejemplo n.º 15
0
		protected override void CanvasContextMenu ()
		{
			if (currentEvent.type != EventType.MouseDown || currentEvent.button != 1 || currentEvent.clickCount != 1 || FsmEditor.Active == null){
				return;
			}	
			GenericMenu canvasMenu = new GenericMenu ();
			canvasMenu.AddItem (FsmContent.createState, false, delegate() {
				State state= FsmEditorUtility.AddNode<State>(mousePosition,FsmEditor.Active);
				state.IsStartNode=FsmEditor.Active.GetStartNode() == null;
				FsmEditorUtility.UpdateNodeColor(state);
			});
			canvasMenu.AddItem (FsmContent.createSubFsm, false, delegate() {
				StateMachine stateMachine=FsmEditorUtility.AddNode<StateMachine>(mousePosition,FsmEditor.Active);
				stateMachine.IsStartNode=FsmEditor.Active.GetStartNode() == null;
				FsmEditorUtility.UpdateNodeColor(stateMachine);
			});

			canvasMenu.AddItem (FsmContent.copy, false, delegate() {
				Pasteboard.Copy(new List<Node>(){FsmEditor.Active});
			});

			if (Pasteboard.CanPaste ()) {
				canvasMenu.AddItem (FsmContent.paste, false, delegate() {
					Pasteboard.Paste(mousePosition,FsmEditor.Active);
				});
			}
			canvasMenu.AddSeparator ("");
			if (Selection.activeGameObject != null) {
				canvasMenu.AddItem (FsmContent.addToSelection, false, delegate() {
					foreach(GameObject go in Selection.gameObjects){
						ICodeBehaviour behaviour = go.AddComponent<ICodeBehaviour>();
						behaviour.stateMachine = FsmEditor.Active.Root;
						EditorUtility.SetDirty(behaviour);

					}
					SelectGameObject(Selection.activeGameObject);
				});
				canvasMenu.AddItem (FsmContent.bindToGameObject, false, delegate() {
					foreach(GameObject go in Selection.gameObjects){
						ICodeBehaviour behaviour = go.AddComponent<ICodeBehaviour>();
						behaviour.stateMachine = (StateMachine)FsmUtility.Copy(FsmEditor.Active.Root);//FsmEditor.Active.Root;
						EditorUtility.SetDirty(behaviour);
						
					}
					SelectGameObject(Selection.activeGameObject);
				});
			} else {
				canvasMenu.AddDisabledItem(FsmContent.addToSelection);	
				canvasMenu.AddDisabledItem(FsmContent.bindToGameObject);
			}

			if (FsmEditor.Active.Root != null && !EditorUtility.IsPersistent(FsmEditor.Active.Root)) {
				canvasMenu.AddItem (FsmContent.saveAsAsset, false, delegate() {
					string mPath = EditorUtility.SaveFilePanelInProject (
						"Save StateMachine as Asset",
						"New StateMachine.asset",
						"asset", "");
					if(mPath != null){
						StateMachine stateMachine=(StateMachine)FsmUtility.Copy(FsmEditor.Active.Root);
						AssetDatabase.CreateAsset(stateMachine,mPath);
						AssetDatabase.SaveAssets();
						FsmEditorUtility.ParentChilds(stateMachine);
					}
				});
			} else {
				canvasMenu.AddDisabledItem(FsmContent.saveAsAsset);			
			}
			canvasMenu.ShowAsContext ();
		}
Ejemplo n.º 16
0
    protected override void Init()
    {
        base.Init();

        behavior = gameObject.GetBehaviour();
    }
Ejemplo n.º 17
0
		public void Init(ICodeBehaviour component){
			this.owner = component;
			this.Root.SetVariable ("Owner", this.owner.gameObject);
			this.isInitialized = true;
		}
Ejemplo n.º 18
0
        public static bool ObjectTitlebar(UnityEngine.Object targetObject, bool foldout, ref bool enabled, GenericMenu settings)
        {
            int        controlID = EditorGUIUtility.GetControlID(FocusType.Passive);
            GUIContent content   = new GUIContent(targetObject.name.Replace("/", "."), targetObject.GetTooltip());

            Debug.Log(FsmEditorStyles.inspectorTitle.fixedWidth);
            Rect position = GUILayoutUtility.GetRect(GUIContent.none, FsmEditorStyles.inspectorTitle);

            position.x     += 1f;
            position.width -= 3f;
            Rect rect  = new Rect(position.x + (float)FsmEditorStyles.inspectorTitle.padding.left, position.y + (float)FsmEditorStyles.inspectorTitle.padding.top, 16f, 16f);
            Rect rect1 = new Rect(position.xMax - (float)FsmEditorStyles.inspectorTitle.padding.right - 2f - 16f, rect.y, 16f, 16f);
            Rect rect4 = rect1;

            rect4.x = rect4.x - 18f;

            Rect rect2 = new Rect(position.x + 2f + 2f + 16f * 2, rect.y, 100f, rect.height)
            {
                xMax = rect4.xMin - 2f
            };
            Rect rect3 = new Rect(position.x + 16f, rect.y, 16f, 16f);

            enabled = GUI.Toggle(rect3, enabled, GUIContent.none);
            string url = targetObject.GetHelpUrl();

            if (ErrorChecker.HasErrors(targetObject))
            {
                Rect rect5 = rect4;
                rect5.y += 1.0f;
                if (!string.IsNullOrEmpty(url))
                {
                    rect5.x    = rect5.x - 18f;
                    rect2.xMax = rect5.x;
                }

                GUI.Label(rect5, FsmEditorStyles.errorIcon, FsmEditorStyles.inspectorTitleText);
            }

            if (GUI.Button(rect1, FsmEditorStyles.popupIcon, FsmEditorStyles.inspectorTitleText))
            {
                settings.ShowAsContext();
            }

            if (!string.IsNullOrEmpty(url) && GUI.Button(rect4, FsmEditorStyles.helpIcon, FsmEditorStyles.inspectorTitleText))
            {
                Application.OpenURL(url);
            }

            EventType eventType = Event.current.type;

            if (eventType != EventType.MouseDown)
            {
                if (eventType == EventType.Repaint)
                {
                    FsmEditorStyles.inspectorTitle.Draw(position, GUIContent.none, controlID, foldout);
                    Color color = GUI.contentColor;
                    if (FsmEditor.Active != null && FsmEditor.Active.Owner != null)
                    {
                        ICodeBehaviour behaviour = FsmEditor.Active.Owner;
                        if (behaviour.ActiveNode is State && (behaviour.ActiveNode as State).ActiveAction == targetObject)
                        {
                            GUI.contentColor = Color.green;
                        }
                    }
                    FsmEditorStyles.inspectorTitleText.Draw(rect2, content, controlID, foldout);
                    GUI.contentColor = color;
                }
            }
            position.width = 15;

            bool flag = FsmGUIUtility.DoToggleForward(position, controlID, foldout, GUIContent.none, GUIStyle.none);

            return(flag);
        }
Ejemplo n.º 19
0
 private void Start()
 {
     _codeBehaviour = gameObject.transform.parent.gameObject.GetBehaviour();
 }