Inheritance: System.Object
Exemplo n.º 1
0
        // draws visuals for an event
        void LayoutEventVisuals(AnimEvent animEvent, bool selected, Rect eventRect, string labelText, Rect labelRect)
        {
            // Color differently if selected
            Color eventColor   = selected ? COLOR_UNITY_BLUE : Color.grey;
            Color eventBGColor = selected ? COLOR_EVENT_LABEL_BG_SELECTED : COLOR_EVENT_LABEL_BG;

            //DrawRect( new Rect(eventRect) { width = EVENT_WIDTH }, eventColor  );
            DrawRect(labelRect, eventBGColor);
            GUI.Label(new Rect(labelRect)
            {
                yMin = labelRect.yMin - 4
            }, labelText, new GUIStyle(Styles.TIMELINE_EVENT_TEXT)
            {
                normal = { textColor = eventColor }
            });
            if (selected)
            {
                GUI.color = COLOR_UNITY_BLUE;
            }
            GUI.Box(new Rect(eventRect.xMin - 2, eventRect.yMin, 6, 20), Contents.EVENT_MARKER, new GUIStyle(Styles.TIMELINE_EVENT_TICK)
            {
                normal = { textColor = eventColor }
            });
            GUI.color = Color.white;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resolves the event and returns an AnimEventHandle.
        /// </summary>
        public AnimEventHandle ResolveOn(AnimEvent animEvent, BattlerPuppet battlerPuppet)
        {
            int hash = animsHashes[Random.Range(0, animsHashes.Length)];

            battlerPuppet.animator.Play(hash);
            return(new AnimEventHandle(animEvent, battlerPuppet, hash));
        }
Exemplo n.º 3
0
 public void NotifyAllListeners(AnimEvent animEvent, System.Object context = null)
 {
     m_listeners.ForEach(delegate(Listener lsn){
         lsn.OnEvent(animEvent, _owner, context);
     }
                         );
 }
Exemplo n.º 4
0
 protected void SendEvent(AnimEvent id, object val = null)
 {
     if (null != mOnAnimListener)
     {
         mOnAnimListener(id, val);
     }
 }
Exemplo n.º 5
0
 protected override void OnEvent(AnimEvent e, float time, float weight)
 {
     if (!(e is CameraShake))
     {
         return;
     }
     this.mCameraShakeOffset = (e as CameraShake).CalcOffset(time, this.mCameraShakeSeedX, this.mCameraShakeSeedY);
 }
Exemplo n.º 6
0
        public void OnEvent(EAnimEventType p_Type)
        {
            AnimEvent animEvent = m_animEvents[(Int32)p_Type];

            if (animEvent != null)
            {
                animEvent.InvokeCallbacks();
            }
        }
Exemplo n.º 7
0
    private void initAnimEvent()
    {
        animEvent = GetComponent<AnimEvent>();
        if(animEvent == null)
        {
            animEvent = gameObject.AddComponent<AnimEvent>();
        }

        //animEvent.AddAnimEvent()
    }
Exemplo n.º 8
0
        public void RegisterAnimationCallback(EAnimEventType p_Type, Action p_Callback)
        {
            AnimEvent animEvent = m_animEvents[(Int32)p_Type];

            if (animEvent == null)
            {
                animEvent = (m_animEvents[(Int32)p_Type] = new AnimEvent());
            }
            animEvent.RegisterCallback(p_Callback);
        }
Exemplo n.º 9
0
    private void initAnimEvent()
    {
        animEvent = GetComponent <AnimEvent>();
        if (animEvent == null)
        {
            animEvent = gameObject.AddComponent <AnimEvent>();
        }

        //animEvent.AddAnimEvent()
    }
Exemplo n.º 10
0
        // Handles gui events for an event
        void LayoutEventGuiEvents(Rect rect, AnimEvent animEvent, bool selected, Rect eventRect, string labelText, Rect labelRect)
        {
            Rect eventClickRect = new Rect(eventRect)
            {
                xMin = eventRect.xMin + EVENT_CLICK_OFFSET, width = EVENT_CLICK_WIDTH
            };

            //
            // Frame clicking events
            //

            Event e = Event.current;
            bool  mouseContained = eventClickRect.Contains(e.mousePosition) || labelRect.Contains(e.mousePosition);    // Can click on either label or event bar

            // Move cursor (when selected, it can be dragged to move it)
            EditorGUIUtility.AddCursorRect(eventClickRect, MouseCursor.MoveArrow);

            if (m_dragState == eDragState.None && mouseContained && e.button == 0)
            {
                //
                // Handle Event Selection
                //
                if ((selected == false || e.control == true) && e.type == EventType.MouseDown)
                {
                    // Started clicking unselected - start selecting
                    SelectEvent(animEvent);
                    GUI.FocusControl("none");
                    e.Use();
                }

                if (selected && e.control == false && m_selectedEvents.Count > 1 && e.type == EventType.MouseUp)
                {
                    // Had multiple selected, and clicked on just one, deselect others. Done on mouse up so we can start the drag if we want
                    SelectEvent(animEvent);
                    GUI.FocusControl("none");
                    e.Use();
                }

                if (selected && e.type == EventType.MouseDown)
                {
                    GUI.FocusControl("none");
                    // Clicked alredy selected item, consume event so it doesn't get deseleccted when starting a move
                    e.Use();
                }

                //
                // Handle start move frame drag
                //
                if (e.type == EventType.MouseDrag)
                {
                    m_dragState = eDragState.MoveEvent;
                }
            }
        }
Exemplo n.º 11
0
 private void ProcessAnimationEvents()
 {
     for (int index1 = 0; index1 < this.mAnimationStates.Count; ++index1)
     {
         AnimationPlayer.AnimationStateSource mAnimationState = this.mAnimationStates[index1];
         AnimDef clip   = mAnimationState.Clip;
         float   length = clip.Length;
         if ((double)mAnimationState.Weight > 0.0 && clip.events != null)
         {
             for (int index2 = 0; index2 < clip.events.Length; ++index2)
             {
                 AnimEvent e = clip.events[index2];
                 if (!Object.op_Equality((Object)e, (Object)null) && this.IsEventAllowed(e))
                 {
                     float num1 = Mathf.Min(e.Start, length);
                     float num2 = Mathf.Min(e.End, length);
                     float num3 = mAnimationState.WrapMode != 2 || (double)mAnimationState.Time >= (double)mAnimationState.TimeOld ? mAnimationState.TimeOld : mAnimationState.TimeOld - length;
                     if ((double)num1 < (double)length)
                     {
                         if ((double)num3 <= (double)num1 && (double)num1 < (double)mAnimationState.Time)
                         {
                             this.OnEventStart(e, mAnimationState.Weight);
                             e.OnStart(((Component)this).get_gameObject());
                         }
                     }
                     else if ((double)num3 < (double)num1 && (double)num1 <= (double)mAnimationState.Time)
                     {
                         this.OnEventStart(e, mAnimationState.Weight);
                         e.OnStart(((Component)this).get_gameObject());
                     }
                     if ((double)num1 <= (double)mAnimationState.Time && (double)mAnimationState.Time < (double)num2)
                     {
                         float num4 = e.End - e.Start;
                         this.OnEvent(e, mAnimationState.Time, mAnimationState.Weight);
                         e.OnTick(((Component)this).get_gameObject(), (double)num4 <= 0.0 ? 0.0f : (mAnimationState.Time - e.Start) / num4);
                     }
                     if ((double)num2 < (double)length)
                     {
                         if ((double)num3 <= (double)num2 && (double)num2 < (double)mAnimationState.Time)
                         {
                             this.OnEventEnd(e, mAnimationState.Weight);
                             e.OnEnd(((Component)this).get_gameObject());
                         }
                     }
                     else if ((double)num3 < (double)num2 && (double)num2 <= (double)mAnimationState.Time)
                     {
                         this.OnEventEnd(e, mAnimationState.Weight);
                         e.OnEnd(((Component)this).get_gameObject());
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 12
0
	/// <summary>
	/// Creates an instance.
	/// </summary>
	/// <param name='animEvent'>
	/// Animation event.
	/// </param>
	private void CreateInstance (AnimEvent animEvent)
	{
		Quaternion rot = GenerateRandomRotation (animEvent);
		animEvent.fireTime++;
		
		if (animEvent.castToSurface == false)
			Instantiate (animEvent.effect, animEvent.target.position, rot);
		else {
			RaycastHit hit;
			Physics.Raycast (animEvent.target.position, -Vector3.up, out hit, 5);
			Instantiate (animEvent.effect, hit.point, rot);
		}
	}
Exemplo n.º 13
0
 private void OnAnimEvent(AnimationController controller, AnimEvent evt)
 {
     if (evt == AnimEvent.LOOP && m_isAttacking)
     {
         if (Random.Range(0f, 1f) > m_attackSuccessRate)
         {
             m_target.Break();
             m_target             = null;
             transform.localScale = new Vector3(1, 1, 1);
             m_rigidbody.mass     = 1;
             m_getBack            = true;
             controller.SelectAnim(0);
             m_isAttacking = false;
         }
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// Dispatch the given anim event to the BattlerPuppet.
 /// </summary>
 public AnimEventHandle DispatchAnimEvent(AnimEvent animEvent, BattlerPuppet puppet)
 {
     if (animEventResolverTable.ContainsKey(animEvent.animEventType))
     {
         return(animEventResolverTable[animEvent.animEventType].ResolveOn(animEvent, puppet));
     }
     else if (animEventResolverTable.ContainsKey(animEvent.fallbackType))
     {
         return(animEventResolverTable[animEvent.fallbackType].ResolveOn(animEvent, puppet));
     }
     else if ((animEvent.flags & AnimEvent.Flags.IsMandatory) == AnimEvent.Flags.IsMandatory)
     {
         Util.Crash(puppet.gameObject.name + " failed to resolve mandatory AnimEvent of type " + animEvent.animEventType + " and fallback type " + animEvent.fallbackType);
     }
     return(null);
 }
Exemplo n.º 15
0
    // Use this for initialization
    void Start()
    {
        animator = GetComponent <Animator>();

        animEvent = gameObject.GetComponent <AnimEvent>();
        if (animEvent == null)
        {
            animEvent = gameObject.AddComponent <AnimEvent>();
        }

        trail = gameObject.GetComponent <TrailWeapon>();
        if (trail == null)
        {
            trail          = gameObject.AddComponent <TrailWeapon>();
            trail.TrailObj = gameObject.transform.Find2("weapon_trail", false).GetComponent <WeaponTrail>();
        }
    }
Exemplo n.º 16
0
    /// <summary>
    /// Creates an instance.
    /// </summary>
    /// <param name='animEvent'>
    /// Animation event.
    /// </param>
    private void CreateInstance(AnimEvent animEvent)
    {
        Quaternion rot = GenerateRandomRotation(animEvent);

        animEvent.fireTime++;

        if (animEvent.castToSurface == false)
        {
            Instantiate(animEvent.effect, animEvent.target.position, rot);
        }
        else
        {
            RaycastHit hit;
            Physics.Raycast(animEvent.target.position, -Vector3.up, out hit, 5);
            Instantiate(animEvent.effect, hit.point, rot);
        }
    }
Exemplo n.º 17
0
    void OnAnimEvent(Entity id, AnimEvent animType)
    {
        switch (animType)
        {
        case AnimEvent.SimpleAttackStart:
            EntityUtility.Instance.RemoveAndPushEntityComponentData <MoveComponent>(id);
            EntityUtility.Instance.RemoveAndPushEntityComponentData <JumpComponent>(id);
            break;

        case AnimEvent.SimpleAttackEnd:
            EntityUtility.Instance.PopAndAddEntityComponentData <MoveComponent>(id);
            EntityUtility.Instance.PopAndAddEntityComponentData <JumpComponent>(id);
            break;

        default:
            break;
        }
    }
Exemplo n.º 18
0
    public override void HandleAnimEvent(AnimEvent eventType)
    {
        base.HandleAnimEvent(eventType);
        switch (eventType)
        {
        case AnimEvent.SimpleAttackStart:
            break;

        case AnimEvent.SimpleAttackEnd:
            break;

        case AnimEvent.SimpleAttackEffect:
            HandleSlashEffect();
            break;

        default:
            break;
        }
    }
Exemplo n.º 19
0
        /// <summary>
        /// Init this tree by constructing the behavior tree.
        /// Root node should be returned.
        /// </summary>
        public virtual BTNode Init()
        {
            _database = GetComponent<BTDatabase>();
            if (_database == null) {
                _database = gameObject.AddComponent<BTDatabase>();
            }

            //每个行为树上挂一个动画事件的接收器
            if(_useAnimEvent)
            {
                _animEvent = GetComponent<AnimEvent>();
                if (_animEvent == null)
                {
                    _animEvent = gameObject.AddComponent<AnimEvent>();
                }
            }

            return null;
        }
Exemplo n.º 20
0
    public void PlayEvent(GameSoundEvents.Event ev)
    {
        if (AudioDebug.Get().debugGameEventSounds)
        {
            Debug.Log("GameSoundEvent: " + ev.Name);
        }
        List <AnimEvent> events = GameAudioSheets.Get().GetEvents(ev.Name);

        if (events != null)
        {
            Vector2 v = base.transform.GetPosition();
            for (int i = 0; i < events.Count; i++)
            {
                AnimEvent  animEvent  = events[i];
                SoundEvent soundEvent = animEvent as SoundEvent;
                if (soundEvent == null || soundEvent.sound == null)
                {
                    break;
                }
                if (CameraController.Instance.IsAudibleSound(v, soundEvent.sound))
                {
                    if (AudioDebug.Get().debugGameEventSounds)
                    {
                        Debug.Log("GameSound: " + soundEvent.sound);
                    }
                    float value = 0f;
                    if (lastTimePlayed.TryGetValue(soundEvent.soundHash, out value))
                    {
                        if (Time.time - value > soundEvent.minInterval)
                        {
                            SoundEvent.PlayOneShot(soundEvent.sound, v);
                        }
                    }
                    else
                    {
                        SoundEvent.PlayOneShot(soundEvent.sound, v);
                    }
                    lastTimePlayed[soundEvent.soundHash] = Time.time;
                }
            }
        }
    }
Exemplo n.º 21
0
        public override void Activate(BTDatabase database)
        {
            base.Activate(database);

            _animEvent = _go.GetComponent<AnimEvent>();
            if (_animEvent == null)
            {
                _animEvent = _go.AddComponent<AnimEvent>();
            }

            _trail = _go.GetComponent<TrailWeapon>();
            if (_trail == null)
            {
                _trail = _go.AddComponent<TrailWeapon>();
                _trail.TrailObj = _go.transform.Find2("weapon_trail", false).GetComponent<WeaponTrail>();
            }

            //监测攻击完成事件
            EventDispatcher.AddEventListener<AnimatorStateInfo>(BTreeEventConfig.OnAnimationFinished, onAttackFinished);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Init this tree by constructing the behavior tree.
        /// Root node should be returned.
        /// </summary>
        public virtual BTNode Init()
        {
            _database = GetComponent <BTDatabase>();
            if (_database == null)
            {
                _database = gameObject.AddComponent <BTDatabase>();
            }

            //每个行为树上挂一个动画事件的接收器
            if (_useAnimEvent)
            {
                _animEvent = GetComponent <AnimEvent>();
                if (_animEvent == null)
                {
                    _animEvent = gameObject.AddComponent <AnimEvent>();
                }
            }

            return(null);
        }
Exemplo n.º 23
0
        public override void Activate(BTDatabase database)
        {
            base.Activate(database);

            _animEvent = _go.GetComponent <AnimEvent>();
            if (_animEvent == null)
            {
                _animEvent = _go.AddComponent <AnimEvent>();
            }

            _trail = _go.GetComponent <TrailWeapon>();
            if (_trail == null)
            {
                _trail          = _go.AddComponent <TrailWeapon>();
                _trail.TrailObj = _go.transform.Find2("weapon_trail", false).GetComponent <WeaponTrail>();
            }

            //监测攻击完成事件
            EventDispatcher.AddEventListener <AnimatorStateInfo>(BTreeEventConfig.OnAnimationFinished, onAttackFinished);
        }
Exemplo n.º 24
0
    void Start()
    {
        animator = GetComponent <Animator>();
        //animatorTest();
        //animEvent.AddAnimEvent(enemy, clip, 0.5f, onAttack2);

        trail = GetComponent <TrailWeapon>();

        animEvent = GetComponent <AnimEvent>();
        if (animEvent == null)
        {
            animEvent = gameObject.AddComponent <AnimEvent>();
        }

//         animEvent.AddAnimEvent(clip, 0.2f, trail.TrailStart);
//         animEvent.AddAnimEvent(clip, 0.6f, trail.TrailStop);

        //animEvent.AddAnimEvent3(enemy, clip, 0.2f, onAttack2);
        //animEvent.AddAnimEvent3(enemy, clip, 0.6f, onAttack3);
    }
Exemplo n.º 25
0
        // NB: if draw is true, it'll draw stuff only, otherwise it'll handle events only.
        void LayoutEvent(Rect rect, AnimEvent animEvent, AnimEventLayoutData layoutData, bool draw)
        {
            // check if it's visible on timeline
            if (layoutData.start > rect.xMax || layoutData.end < rect.xMin)
            {
                return;
            }

            float heightOffset = (layoutData.heightOffset * TIMELINE_EVENT_HEIGHT);
            Rect  eventRect    = new Rect(layoutData.start, heightOffset, 0, TIMELINE_EVENT_HEIGHT);
            Rect  labelRect    = new Rect(layoutData.start + 2, heightOffset, layoutData.textWidth, TIMELINE_EVENT_HEIGHT - 2);

            if (draw)
            {
                LayoutEventVisuals(animEvent, layoutData.selected, eventRect, layoutData.text, labelRect);
            }
            else
            {
                LayoutEventGuiEvents(rect, animEvent, layoutData.selected, eventRect, layoutData.text, labelRect);
            }
        }
Exemplo n.º 26
0
 protected override void OnEventStart(AnimEvent e, float weight)
 {
     if (e is ToggleCamera)
     {
         this.mCameraID = (e as ToggleCamera).CameraID;
         if (this.mCameraID >= 0 && this.mCameraID <= 1)
         {
             return;
         }
         Debug.LogError((object)("Invalid CameraID: " + (object)this.mCameraID));
     }
     else
     {
         if (!(e is CameraShake))
         {
             return;
         }
         this.mCameraShakeSeedX = Random.get_value();
         this.mCameraShakeSeedY = Random.get_value();
     }
 }
Exemplo n.º 27
0
    /// <summary>
    /// Generates a random rotation.
    /// </summary>
    /// <returns>
    /// A random quaternion rotation.
    /// </returns>
    /// <param name='animEvent'>
    /// Animation event.
    /// </param>
    private Quaternion GenerateRandomRotation(AnimEvent animEvent)
    {
        Quaternion quaternion = Quaternion.identity;

        switch (animEvent.rotation)
        {
        case Rotation.MatchTarget:
            quaternion = animEvent.target.rotation;
            break;

        case Rotation.Random_X:
            quaternion = Quaternion.Euler(new Vector3(UnityEngine.Random.Range(0f, 361f), 0, 0));
            break;

        case Rotation.Random_Y:
            quaternion = Quaternion.Euler(new Vector3(0, UnityEngine.Random.Range(0f, 361f), 0));
            break;

        case Rotation.Random_Z:
            quaternion = Quaternion.Euler(new Vector3(0, 0, UnityEngine.Random.Range(0f, 361f)));
            break;

        case Rotation.Random_XY:
            quaternion = Quaternion.Euler(new Vector3(UnityEngine.Random.Range(0f, 361f), UnityEngine.Random.Range(0f, 361f), 0));
            break;

        case Rotation.Random_XZ:
            quaternion = Quaternion.Euler(new Vector3(UnityEngine.Random.Range(0f, 361f), 0, UnityEngine.Random.Range(0f, 361f)));
            break;

        case Rotation.Random_YZ:
            quaternion = Quaternion.Euler(new Vector3(0, UnityEngine.Random.Range(0f, 361f), UnityEngine.Random.Range(0f, 361f)));
            break;

        case Rotation.Random_XYZ:
            quaternion = Quaternion.Euler(new Vector3(UnityEngine.Random.Range(0f, 361f), UnityEngine.Random.Range(0f, 361f), UnityEngine.Random.Range(0f, 361f)));
            break;
        }
        return(quaternion);
    }
Exemplo n.º 28
0
 private void CreateSound(string file_name, string anim_name, string type, float min_interval, string sound_name, int frame)
 {
     if (!string.IsNullOrEmpty(sound_name))
     {
         HashedString key       = file_name + "." + anim_name;
         AnimEvent    animEvent = CreateSoundOfType(type, file_name, sound_name, frame, min_interval);
         if (animEvent == null)
         {
             Debug.LogError("Unknown sound type: " + type);
         }
         else
         {
             List <AnimEvent> value = null;
             if (!events.TryGetValue(key, out value))
             {
                 value       = new List <AnimEvent>();
                 events[key] = value;
             }
             value.Add(animEvent);
         }
     }
 }
Exemplo n.º 29
0
    void OnAnimEvent(Entity id, AnimEvent animType)
    {
        switch (animType)
        {
        case AnimEvent.SimpleAttackStart:
            EntityUtility.Instance.RemoveAndPushEntityComponentData <MoveComponent>(id);
            EntityUtility.Instance.RemoveAndPushEntityComponentData <JumpComponent>(id);
            break;

        case AnimEvent.SimpleAttackEnd:
            EntityUtility.Instance.PopAndAddEntityComponentData <MoveComponent>(id);
            EntityUtility.Instance.PopAndAddEntityComponentData <JumpComponent>(id);
            break;

        default:
            Transform     characterTrans = EntityUtility.Instance.GetComponent <Transform>(id);
            CharacterBase character      = characterTrans.GetComponent <CharacterBase>();
            if (character != null)
            {
                character.HandleAnimEvent(animType);
            }
            break;
        }
    }
Exemplo n.º 30
0
	/// <summary>
	/// Fires a method based on the string given when setting up the event array.
	/// </summary>
	/// <param name='animEvent'>
	/// Animation event.
	/// </param>
	private void FireMethod (AnimEvent animEvent)
	{
		Debug.Log ("FireMethod: " + animEvent.ToString() );
		animEvent.fireTime++;
		animEvent.target.SendMessage (animEvent.MethodCall);
	}
Exemplo n.º 31
0
    void Start()
    {
        animator = GetComponent<Animator>();
        //animatorTest();
        //animEvent.AddAnimEvent(enemy, clip, 0.5f, onAttack2);

        trail = GetComponent<TrailWeapon>();

        animEvent = GetComponent<AnimEvent>();
        if(animEvent == null)
            animEvent = gameObject.AddComponent<AnimEvent>();

        //         animEvent.AddAnimEvent(clip, 0.2f, trail.TrailStart);
        //         animEvent.AddAnimEvent(clip, 0.6f, trail.TrailStop);

        //animEvent.AddAnimEvent3(enemy, clip, 0.2f, onAttack2);
        //animEvent.AddAnimEvent3(enemy, clip, 0.6f, onAttack3);
    }
Exemplo n.º 32
0
 public virtual void HandleAnimEvent(AnimEvent eventType)
 {
 }
Exemplo n.º 33
0
        void LayoutBottomBarEventData(Rect rect)
        {
            EditorGUI.BeginChangeCheck();

            float xOffset = 10;
            float width   = 55;

            GUI.Label(new Rect(xOffset, 1, width, rect.height), "Event:", EditorStyles.boldLabel);

            // Function Name

            xOffset += width;
            width    = 100;

            AnimEvent animEvent = m_selectedEvents[0];

            // Give gui control name using it's time and function name so it can be auto-selected when creating new evnet

            GUI.SetNextControlName("EventFunctionName");
            animEvent.m_functionName = EditorGUI.TextField(new Rect(xOffset, 2, width, rect.height + 5), animEvent.m_functionName, EditorStyles.miniTextField);

            if (m_focusEvent == animEvent)
            {
                if (GUI.GetNameOfFocusedControl() == "EventFunctionName")
                {
                    m_focusEvent = null;
                }
                EditorGUI.FocusTextInControl("EventFunctionName");
            }

            xOffset += width + 5;
            width    = 60;

            GUI.Label(new Rect(xOffset, 0, width, rect.height), "Parameter:", EditorStyles.miniLabel);

            xOffset += width;
            width    = 60;

            animEvent.m_paramType = (eAnimEventParameter)EditorGUI.EnumPopup(new Rect(xOffset, 2, width, rect.height), animEvent.m_paramType as System.Enum);

            switch (animEvent.m_paramType)
            {
            case eAnimEventParameter.Int:
            {
                xOffset += width + 5;
                width    = 60;
                animEvent.m_paramInt = EditorGUI.IntField(new Rect(xOffset, 2, width, rect.height - 3), animEvent.m_paramInt, EditorStyles.miniTextField);
            } break;

            case eAnimEventParameter.Float:
            {
                xOffset += width + 5;
                width    = 60;
                animEvent.m_paramFloat = EditorGUI.FloatField(new Rect(xOffset, 2, width, rect.height - 3), animEvent.m_paramFloat, EditorStyles.miniTextField);
            } break;

            case eAnimEventParameter.String:
            {
                xOffset += width + 5;
                width    = 60;
                animEvent.m_paramString = EditorGUI.TextField(new Rect(xOffset, 2, width, rect.height), animEvent.m_paramString, EditorStyles.miniTextField);
            } break;

            case eAnimEventParameter.Object:
            {
                xOffset += width + 5;
                width    = 150;
                animEvent.m_paramObjectReference = EditorGUI.ObjectField(new Rect(xOffset, 2, width, rect.height - 3), animEvent.m_paramObjectReference, typeof(Object), false);
            } break;

            default: break;
            }

            // Align options to to right

            xOffset  = rect.width;
            width    = 110;
            xOffset -= width;

            // Prefix
            animEvent.m_usePrefix = GUI.Toggle(new Rect(xOffset, 0, width, rect.height), animEvent.m_usePrefix, "Add 'Anim' Prefix", Styles.TIMELINE_EVENT_TOGGLE);

            width    = 105;
            xOffset -= width;

            // Send updwards
            animEvent.m_messageOptions = GUI.Toggle(new Rect(xOffset, 0, width, rect.height),
                                                    animEvent.m_messageOptions == SendMessageOptions.RequireReceiver,
                                                    "Require Receiver", Styles.TIMELINE_EVENT_TOGGLE) ? SendMessageOptions.RequireReceiver : SendMessageOptions.DontRequireReceiver;

            width    = 90;
            xOffset -= width;

            // Send updwards
            animEvent.m_sendUpwards = GUI.Toggle(new Rect(xOffset, 0, width, rect.height), animEvent.m_sendUpwards, "Send Upwards", Styles.TIMELINE_EVENT_TOGGLE);

            if (EditorGUI.EndChangeCheck())
            {
                // Set default tag options to last tag edited (when new tag is created it'll use these options)
                m_defaultEventMessageOptions = animEvent.m_messageOptions;
                m_defaultEventSendUpwards    = animEvent.m_sendUpwards;
                m_defaultEventUsePrefix      = animEvent.m_usePrefix;

                // Apply events
                ApplyChanges();
            }
        }
Exemplo n.º 34
0
        void LayoutEvents(Rect rect)
        {
            Event e = Event.current;

            if (e.type == EventType.mouseDown && e.button == 0 && rect.Contains(e.mousePosition) && m_playing == false)
            {
                // Move timeline
                m_animTime = SnapTimeToFrameRate(GuiPosToAnimTime(rect, e.mousePosition.x));
            }
            if (e.type == EventType.MouseDown && e.button == 0 && e.clickCount == 2 && rect.Contains(e.mousePosition))
            {
                // Double click for new event at that time

                // New event
                InsertEvent(GuiPosToAnimTime(rect, e.mousePosition.x), true);
                e.Use();
            }

            GUI.BeginGroup(rect);

            if (m_events.Count == 0)
            {
                GUI.Label(new Rect(0, 0, rect.width, rect.height), "Double click to insert event", EditorStyles.centeredGreyMiniLabel);
            }

            // Layout events. This is done in 4 stages so that selected items are drawn on top of (after) non-selected ones, but have their gui events handled first.

            // Calc some metadata about each event (start/end position on timeline, etc). This is stored in a temporary array, parallel to events
            AnimEventLayoutData[] eventTimelineData = new AnimEventLayoutData[m_events.Count];

            // First loop over and calculate start/end positions of events
            for (int i = 0; i < m_events.Count; ++i)
            {
                AnimEvent           animEvent = m_events[i];
                AnimEventLayoutData eventData = new AnimEventLayoutData();
                eventTimelineData[i] = eventData;

                eventData.start     = AnimTimeToGuiPos(rect, SnapTimeToFrameRate(animEvent.m_time));
                eventData.text      = animEvent.m_functionName;   //.Replace(ANIM_EVENT_PREFIX,null);
                eventData.textWidth = Styles.TIMELINE_EVENT_TEXT.CalcSize(new GUIContent(eventData.text)).x;
                eventData.end       = eventData.start + eventData.textWidth + 4;
                eventData.selected  = m_selectedEvents.Contains(m_events[i]);
            }

            int maxEventOffset = 0;

            // Now loop over events and calculate the vertical offset of events so that they don't overlap
            for (int i = 0; i < m_events.Count; ++i)
            {
                // Store the offset of everything we're overlapping with in a mask, so we can get the first available offset.
                int usedOffsetsMask      = 0;
                AnimEventLayoutData data = eventTimelineData[i];
                for (int j = i - 1; j >= 0; --j)
                {
                    // check for overlap of items before this one. A
                    AnimEventLayoutData other = eventTimelineData[j];
                    if ((data.start > other.end || data.end < other.start) == false)
                    {
                        // overlaps!
                        usedOffsetsMask |= 1 << (other.heightOffset);
                    }
                }

                // Loop through mask to find first available offset.
                while (data.heightOffset < 32 && (usedOffsetsMask & (1 << data.heightOffset)) != 0)
                {
                    data.heightOffset++;
                }

                if (data.heightOffset > maxEventOffset)
                {
                    maxEventOffset = data.heightOffset;
                }
            }

            // Draw vertical lines where there's an event
            for (int i = 0; i < m_events.Count; ++i)
            {
                DrawRect(new Rect(eventTimelineData[i].start, 0, 1, rect.height), Color.grey);
            }

            // First draw events
            for (int i = 0; i < m_events.Count; ++i)
            {
                LayoutEvent(rect, m_events[i], eventTimelineData[i], true);
            }

            // Then handle gui events in reverse order
            for (int i = m_events.Count - 1; i >= 0; --i)
            {
                LayoutEvent(rect, m_events[i], eventTimelineData[i], false);
            }

            GUI.EndGroup();


            // Draw selection rect
            if (m_dragState == eDragState.SelectEvent && Mathf.Abs(m_selectionMouseStart - e.mousePosition.x) > 1.0f)
            {
                // Draw selection rect
                Rect selectionRect = new Rect(rect)
                {
                    xMin = Mathf.Min(m_selectionMouseStart, e.mousePosition.x), xMax = Mathf.Max(m_selectionMouseStart, e.mousePosition.x)
                };
                DrawRect(selectionRect, COLOR_UNITY_BLUE.WithAlpha(0.1f), COLOR_UNITY_BLUE.WithAlpha(0.6f));
            }

            // Check for unhandled mouse left click. It should deselect any selected events
            if (e.type == EventType.MouseDown && e.button == 0)
            {
                if (rect.Contains(e.mousePosition))
                {
                    ClearSelection();
                    e.Use();
                }
            }

            // Check for unhanlded drag, it should start a select
            if (m_dragState == eDragState.None && e.type == EventType.MouseDrag && e.button == 0)
            {
                if (rect.Contains(e.mousePosition))
                {
                    m_dragState = eDragState.SelectEvent;
                    e.Use();
                }
            }

            if (m_dragState == eDragState.MoveEvent)
            {
                // While moving frame, show the move cursor
                EditorGUIUtility.AddCursorRect(rect, MouseCursor.MoveArrow);
                if (e.type == EventType.MouseDrag)
                {
                    MoveSelectedEvents(e.delta.x);

                    // move the frame
                    e.Use();
                }
                if (e.rawType == EventType.MouseUp && e.button == 0)
                {
                    // Apply the move change
                    ApplyChanges();
                    m_dragState = eDragState.None;
                    e.Use();
                }
            }

            float newTimelineHeight = Mathf.Max((maxEventOffset + 1), 1.5f) * TIMELINE_EVENT_HEIGHT;

            if (newTimelineHeight != m_timelineEventBarHeight)
            {
                m_timelineEventBarHeight = newTimelineHeight;
                Repaint();
            }
        }
Exemplo n.º 35
0
 /// <summary>
 /// Returns true if either primary or fallback types of this anim event can be resolved.
 /// </summary>
 public bool AnimEventIsResolveable(AnimEvent animEvent)
 {
     return(animEventResolverTable.ContainsKey(animEvent.animEventType) || animEventResolverTable.ContainsKey(animEvent.fallbackType));
 }
Exemplo n.º 36
0
    // Use this for initialization
    void Start()
    {
        animator = GetComponent<Animator>();

        animEvent = gameObject.GetComponent<AnimEvent>();
        if (animEvent == null)
        {
            animEvent = gameObject.AddComponent<AnimEvent>();
        }

        trail = gameObject.GetComponent<TrailWeapon>();
        if (trail == null)
        {
            trail = gameObject.AddComponent<TrailWeapon>();
            trail.TrailObj = gameObject.transform.Find2("weapon_trail", false).GetComponent<WeaponTrail>();
        }
    }
Exemplo n.º 37
0
	/// <summary>
	/// Generates a random rotation.
	/// </summary>
	/// <returns>
	/// A random quaternion rotation.
	/// </returns>
	/// <param name='animEvent'>
	/// Animation event.
	/// </param>
	private Quaternion GenerateRandomRotation (AnimEvent animEvent)
	{
		Quaternion quaternion = Quaternion.identity;
		
		switch (animEvent.rotation) {
		case Rotation.MatchTarget:
			quaternion = animEvent.target.rotation;
			break;
		case Rotation.Random_X:
			quaternion = Quaternion.Euler (new Vector3 (UnityEngine.Random.Range (0f, 361f), 0, 0));
			break;
		case Rotation.Random_Y:
			quaternion = Quaternion.Euler (new Vector3 (0, UnityEngine.Random.Range (0f, 361f), 0));
			break;
		case Rotation.Random_Z:
			quaternion = Quaternion.Euler (new Vector3 (0, 0, UnityEngine.Random.Range (0f, 361f)));
			break;
		case Rotation.Random_XY:
			quaternion = Quaternion.Euler (new Vector3 (UnityEngine.Random.Range (0f, 361f), UnityEngine.Random.Range (0f, 361f), 0));
			break;
		case Rotation.Random_XZ:
			quaternion = Quaternion.Euler (new Vector3 (UnityEngine.Random.Range (0f, 361f), 0, UnityEngine.Random.Range (0f, 361f)));
			break;
		case Rotation.Random_YZ:
			quaternion = Quaternion.Euler (new Vector3 (0, UnityEngine.Random.Range (0f, 361f), UnityEngine.Random.Range (0f, 361f)));
			break;
		case Rotation.Random_XYZ:
			quaternion = Quaternion.Euler (new Vector3 (UnityEngine.Random.Range (0f, 361f), UnityEngine.Random.Range (0f, 361f), UnityEngine.Random.Range (0f, 361f)));
			break;
		}
		return quaternion;
	}
Exemplo n.º 38
0
 protected override bool IsEventAllowed(AnimEvent e)
 {
     return(false);
 }