private void ResumeExecutionActionBookmark(PickState pickState, NativeActivityContext context) { Fx.Assert(pickState.ExecuteActionBookmark != null, "This should have been set by the branch."); context.ResumeBookmark(pickState.ExecuteActionBookmark, null); pickState.ExecuteActionBookmark = null; }
private void OnBranchComplete(NativeActivityContext context, ActivityInstance completedInstance) { PickState pickState = this.pickStateVariable.Get(context); ReadOnlyCollection <ActivityInstance> executingChildren = context.GetChildren(); switch (completedInstance.State) { case ActivityInstanceState.Closed: pickState.HasBranchCompletedSuccessfully = true; break; case ActivityInstanceState.Canceled: case ActivityInstanceState.Faulted: if (context.IsCancellationRequested) { if (executingChildren.Count == 0 && !pickState.HasBranchCompletedSuccessfully) { // All of the branches are complete and we haven't had a single // one complete successfully and we've been asked to cancel. context.MarkCanceled(); context.RemoveAllBookmarks(); } } break; } //the last branch should always resume action bookmark if it's still there if (executingChildren.Count == 1 && pickState.ExecuteActionBookmark != null) { ResumeExecutionActionBookmark(pickState, context); } }
private void OnTriggerComplete(NativeActivityContext context, Bookmark bookmark, object state) { PickState pickState = this.pickStateVariable.Get(context); string winningBranch = (string)state; ReadOnlyCollection <ActivityInstance> children = context.GetChildren(); bool resumeAction = true; for (int i = 0; i < children.Count; i++) { ActivityInstance child = children[i]; if (child.Id != winningBranch) { context.CancelChild(child); resumeAction = false; } } if (resumeAction) { ResumeExecutionActionBookmark(pickState, context); } }
private void OnBranchComplete(NativeActivityContext context, System.Activities.ActivityInstance completedInstance) { PickState pickState = this.pickStateVariable.Get(context); ReadOnlyCollection <System.Activities.ActivityInstance> children = context.GetChildren(); switch (completedInstance.State) { case ActivityInstanceState.Closed: pickState.HasBranchCompletedSuccessfully = true; break; case ActivityInstanceState.Canceled: case ActivityInstanceState.Faulted: if ((context.IsCancellationRequested && (children.Count == 0)) && !pickState.HasBranchCompletedSuccessfully) { context.MarkCanceled(); context.RemoveAllBookmarks(); } break; } if ((children.Count == 1) && (pickState.ExecuteActionBookmark != null)) { this.ResumeExecutionActionBookmark(pickState, context); } }
// 碰到 开始追踪 private void OnTouch(Player player) { mPicker = player; DisplayTouchParticle(); mState = PickState.Follow; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var name = property.FindPropertyRelative("Name"); var key = property.FindPropertyRelative("Key"); var oldWidth = position.width; var nameLabelWidth = 42; var keyLabelWidth = 36; var nameWidth = oldWidth * 0.35f; var keyButtonWidth = 42; var keyWidth = oldWidth - nameLabelWidth - keyLabelWidth - nameWidth - keyButtonWidth; position.width = nameLabelWidth; EditorGUI.PrefixLabel(position, new GUIContent("Name")); position.x += nameLabelWidth; position.width = nameWidth; name.stringValue = EditorGUI.TextField(position, name.stringValue); position.x += nameWidth; if (State == PickState.Waiting) { if (CurrentProperty == property.CountRemaining()) { GUI.SetNextControlName("_KeyPicker"); EditorGUI.LabelField(position, "Press any key..."); GUI.FocusControl("_KeyPicker"); return; } GUI.enabled = false; } if (State == PickState.Got && CurrentProperty == property.CountRemaining()) { key.intValue = (int)SavedKeyCode; State = PickState.None; CurrentProperty = -1; } position.width = keyLabelWidth; EditorGUI.PrefixLabel(position, new GUIContent("Key")); position.x += keyLabelWidth; position.width = keyWidth; GUI.Box(position, ((KeyCode)key.intValue).ToString(), EditorStyles.helpBox); position.x += keyWidth; position.width = keyButtonWidth; if (EditorGUI.DropdownButton(position, new GUIContent("Pick"), FocusType.Keyboard)) { WaitForInput(property); } GUI.enabled = true; }
public static void Postfix(ZNetView ___m_nview, bool ___m_picked, ref PickState __state) { //if we're not changing the state, don't change the pick time. //Don't do anything if we're the client. Trust the server in that case. if (__state != null && __state.picked == ___m_picked && ___m_nview.IsOwner()) { ___m_nview.GetZDO().Set("picked_time", __state.picked_time); } }
// 抛物丢出 private void UpdateFlying(uint elapsed) { float seconds = elapsed / 1000f; mFlySpeed += elapsed * 5 / 1000f; float moveDistance = seconds * mFlySpeed + 5 * seconds * seconds * 0.5f; if (mFlyType == FlyType.FLY_OUT) { //Vector3 forward为zero时会有Log报出 Quaternion rotation = new Quaternion(); if (!mFlyDir.Equals(Vector3.zero)) { rotation = Quaternion.LookRotation(mFlyDir); } Vector3 nextPosition = (GetPosition() + (rotation * Vector3.forward) * moveDistance); float heightOffset = mSpeedY * seconds - seconds * seconds * G * 0.5f; mSpeedY -= seconds * G * 4.5f; nextPosition.y += heightOffset; if (!mScene.IsInWalkableRegion(nextPosition.x, nextPosition.z)) { mAliveTime = 0; mState = PickState.Rotate; return; } float horizon = mScene.GetHeight(nextPosition.x, nextPosition.z); if (nextPosition.y <= horizon) { nextPosition.y = horizon; mAliveTime = 0; mState = PickState.Rotate; } SetPosition(nextPosition); } else if (mFlyType == FlyType.DROP_DOWN) { Vector3 nextPosition = new Vector3(mPosition.x, mPosition.y - moveDistance, mPosition.z); float limitY = mScene.GetHeight(nextPosition.x, nextPosition.z); if (nextPosition.y < limitY) { nextPosition.y = limitY; mAliveTime = 0; mState = PickState.Rotate; } SetPosition(nextPosition); } }
public override void OnEnterScene(BaseScene scene, uint instanceid) { base.OnEnterScene(scene, instanceid); if (mRes == null) { return; } // 不飞出 if (mRes.flyOut < 1) { if (mRandomPos) { Vector3 pos = new Vector3(mPosition.x + Random.RandomRange(-1.0f, 1.0f), 0.0f, mPosition.z + Random.RandomRange(-1.0f, 1.0f)); pos.y = mScene.GetHeight(pos.x, pos.z); SetPosition(pos); } mState = PickState.Rotate; } else { // 坠落 if (mFlyType == FlyType.DROP_DOWN) { if (mRandomPos) { Vector3 pos = new Vector3(mPosition.x + Random.RandomRange(-1.0f, 1.0f), 0.0f, mPosition.z + Random.RandomRange(-1.0f, 1.0f)); pos.y = mScene.GetHeight(pos.x, pos.z) + 4.0f; SetPosition(pos); } else { Vector3 pos = new Vector3(mPosition.x, mScene.GetHeight(mPosition.x, mPosition.z) + 4.0f, mPosition.z); SetPosition(pos); } } else // 抛出 { if (mRandomPos) { mFlyDir = new Vector3(Random.RandomRange(-1.0f, 1.0f), 0.0f, Random.RandomRange(-1.0f, 1.0f)); } } mState = PickState.FlyOut; } }
protected override void Execute(NativeActivityContext context) { if (this.branchBodies.Count != 0) { PickState state = new PickState(); this.pickStateVariable.Set(context, state); state.TriggerCompletionBookmark = context.CreateBookmark(new BookmarkCallback(this.OnTriggerComplete)); context.Properties.Add("System.Activities.Statements.Pick.PickState", state); CompletionCallback onCompleted = new CompletionCallback(this.OnBranchComplete); for (int i = this.branchBodies.Count - 1; i >= 0; i--) { context.ScheduleActivity(this.branchBodies[i], onCompleted); } } }
protected override void Execute(NativeActivityContext context) { if (this.branchBodies.Count != 0) { PickState state = new PickState(); this.pickStateVariable.Set(context, state); state.TriggerCompletionBookmark = context.CreateBookmark(new BookmarkCallback(this.OnTriggerComplete)); context.Properties.Add("System.Activities.Statements.Pick.PickState", state); CompletionCallback onCompleted = new CompletionCallback(this.OnBranchComplete); for (int i = this.branchBodies.Count - 1; i >= 0; i--) { context.ScheduleActivity(this.branchBodies[i], onCompleted); } } }
static void OnGlobalKeyPress() { if (Event.current == null) { return; } if (State == PickState.Waiting) { if (Event.current.rawType == EventType.KeyDown || Event.current.rawType == EventType.Used || Event.current.rawType == EventType.ExecuteCommand) { if (!GUI.GetNameOfFocusedControl().Equals("_KeyPicker") && !string.IsNullOrWhiteSpace(GUI.GetNameOfFocusedControl())) { State = PickState.None; CurrentProperty = -1; Debug.Log($"Failed to get key due to '{GUI.GetNameOfFocusedControl()}' having focus!"); Event.current.Use(); EditorUtility.SetDirty(Object.FindObjectOfType <InputScheme>()); } else { State = PickState.Got; SavedKeyCode = Event.current.keyCode; Debug.Log("Got key " + Event.current.keyCode + " for prop " + CurrentProperty); Event.current.Use(); var target = Object.FindObjectOfType <InputScheme>(); if (target) { EditorUtility.SetDirty(target); } } } } }
private void OnTriggerComplete(NativeActivityContext context, Bookmark bookmark, object state) { PickState pickState = this.pickStateVariable.Get(context); string str = (string)state; ReadOnlyCollection <System.Activities.ActivityInstance> children = context.GetChildren(); bool flag = true; for (int i = 0; i < children.Count; i++) { System.Activities.ActivityInstance activityInstance = children[i]; if (activityInstance.Id != str) { context.CancelChild(activityInstance); flag = false; } } if (flag) { this.ResumeExecutionActionBookmark(pickState, context); } }
protected override void UpdateInstance(NativeActivityUpdateContext updateContext) { PickState pickState = updateContext.GetValue(this.pickStateVariable); Fx.Assert(pickState != null, "Pick's Execute must have run by now."); if (updateContext.IsCancellationRequested || pickState.TriggerCompletionBookmark == null) { // do not schedule newly added Branches once a Trigger has successfully completed. return; } CompletionCallback onBranchCompleteCallback = new CompletionCallback(OnBranchComplete); foreach (PickBranchBody body in this.branchBodies) { if (updateContext.IsNewlyAdded(body)) { updateContext.ScheduleActivity(body, onBranchCompleteCallback, null); } } }
private void OnTriggerCompleted(NativeActivityContext context, ActivityInstance completedInstance) { PickState pickState = (PickState)context.Properties.Find(pickStateProperty); if (completedInstance.State == ActivityInstanceState.Closed && pickState.TriggerCompletionBookmark != null) { // We're the first trigger! We win! context.ResumeBookmark(pickState.TriggerCompletionBookmark, context.ActivityInstanceId); pickState.TriggerCompletionBookmark = null; pickState.ExecuteActionBookmark = context.CreateBookmark(new BookmarkCallback(OnExecuteAction)); } else if (!context.IsCancellationRequested) { // We didn't win, but we haven't been requested to cancel yet. // We'll just create a bookmark to keep ourselves from completing. context.CreateBookmark(); } // else // { // No need for an else since default cancelation will cover it! // } }
// 追踪 private bool UpdateFollow(uint elapsed) { if (mPicker == null || mPicker.IsDead()) { return(false); } if (Utility.Distance2D(mPicker.GetPosition(), this.GetPosition()) < 0.5f) { OnPickUp(); mState = PickState.Invalid; return(false); } float seconds = elapsed / 1000f; mFollowSpeed += elapsed * mFollowAcc / 1000f; float moveDistance = seconds * mFollowSpeed + mFollowAcc * seconds * seconds; Vector3 dir = mPicker.GetPosition() - GetPosition(); Quaternion rotation = Quaternion.LookRotation(dir); Vector3 nextPosition = (GetPosition() + (rotation * Vector3.forward) * moveDistance); float offsetY = mPicker.GetPosition().y - nextPosition.y + 2.0f; if (offsetY > float.Epsilon || offsetY < -float.Epsilon) { nextPosition.y += mFollowSpeedY * seconds; } float horizon = mScene.GetHeight(nextPosition.x, nextPosition.z); SetPosition(nextPosition); return(true); }
protected override void Execute(NativeActivityContext context) { if (this.branchBodies.Count == 0) { return; } PickState pickState = new PickState(); this.pickStateVariable.Set(context, pickState); pickState.TriggerCompletionBookmark = context.CreateBookmark(new BookmarkCallback(OnTriggerComplete)); context.Properties.Add(pickStateProperty, pickState); CompletionCallback onBranchCompleteCallback = new CompletionCallback(OnBranchComplete); //schedule every branch to only run trigger for (int i = this.branchBodies.Count - 1; i >= 0; i--) { context.ScheduleActivity(this.branchBodies[i], onBranchCompleteCallback); } }
public void OnPickStateChanged(PickState prevState, PickState currentState, Picker picker, GameObject target) { switch (currentState) { case PickState.None: if (target && target.tag.Equals(TAG_PART)) { Part part = target.GetComponent <Part>(); part.Highlighted = Part.HighlightDegree.None; part.DisconnectFromRigidbody(); if (picker != null) { picker.Reset(); } } else if (target && target.tag.Equals(TAG_BUTTON)) { Highlightable button = target.GetComponentInChildren <Highlightable>(); button.Highlighted = Highlightable.HighlightDegree.None; } break; case PickState.Hovering: if (target && target.tag.Equals(TAG_PART)) { Part part = target.GetComponent <Part>(); part.Highlighted = Part.HighlightDegree.Half; part.DisconnectFromRigidbody(); if (prevState == PickState.Picking) { part.Highlighted = Part.HighlightDegree.None; if (picker != null) { picker.Reset(); } } } else if (target && target.tag.Equals(TAG_BUTTON)) { Highlightable button = target.GetComponentInChildren <Highlightable>(); button.Highlighted = Highlightable.HighlightDegree.Half; } if (currentShelf.CurrentPreset().Type == Preset.PresetType.NewPresetPlaceHolder) { audio.PlayOneShot(audioHover); } break; case PickState.Picking: if (target && target.tag.Equals(TAG_PART) && picker != null) { Part part = target.GetComponent <Part>(); part.Highlighted = Part.HighlightDegree.Full; part.ConnectToRigidbody(picker.MiddlePointContainer.rigidbody, Vector3.zero); pickedAnyPart = true; if (currentShelf.CurrentPreset().Type == Preset.PresetType.NewPresetPlaceHolder) { audio.PlayOneShot(audioPickPart); } } else if (target && target.tag.Equals(TAG_BUTTON)) { Highlightable highlightable = target.GetComponentInChildren <Highlightable>(); highlightable.Highlighted = Highlightable.HighlightDegree.Full; Button3D button = target.transform.parent.GetComponent <Button3D>(); if (button == editButton) { StartCoroutine(OnEditButtonPicked()); } else if (button == saveEditingButton) { StartCoroutine(OnSaveButtonPicked()); } else if (button == cancelEditingButton) { StartCoroutine(OnCancelButtonPicked()); } else if (button == doneEditingButton) { OnDoneButtonPicked(); } audio.PlayOneShot(audioPickButton); } break; } }
protected override void Execute(NativeActivityContext context) { if (this.branchBodies.Count == 0) { return; } PickState pickState = new PickState(); this.pickStateVariable.Set(context, pickState); pickState.TriggerCompletionBookmark = context.CreateBookmark(new BookmarkCallback(OnTriggerComplete)); context.Properties.Add(pickStateProperty, pickState); CompletionCallback onBranchCompleteCallback = new CompletionCallback(OnBranchComplete); //schedule every branch to only run trigger for (int i = this.branchBodies.Count - 1; i >= 0; i--) { context.ScheduleActivity(this.branchBodies[i], onBranchCompleteCallback); } }
void ResumeExecutionActionBookmark(PickState pickState, NativeActivityContext context) { Fx.Assert(pickState.ExecuteActionBookmark != null, "This should have been set by the branch."); context.ResumeBookmark(pickState.ExecuteActionBookmark, null); pickState.ExecuteActionBookmark = null; }
void WaitForInput(SerializedProperty property) { State = PickState.Waiting; CurrentProperty = property.CountRemaining(); }
private void ResumeExecutionActionBookmark(PickState pickState, NativeActivityContext context) { context.ResumeBookmark(pickState.ExecuteActionBookmark, null); pickState.ExecuteActionBookmark = null; }
public static void Prefix(bool picked, ZNetView ___m_nview, bool ___m_picked, ref PickState __state) { __state = new PickState(); __state.picked_time = ___m_nview.GetZDO().GetLong("picked_time", 0L); __state.picked = ___m_picked; }
public static void Postfix(bool picked, ZNetView ___m_nview, bool ___m_picked, ref PickState __state) { if (__state.picked == ___m_picked) { ___m_nview.GetZDO().Set("picked_time", __state.picked_time); } }
private void ResumeExecutionActionBookmark(PickState pickState, NativeActivityContext context) { context.ResumeBookmark(pickState.ExecuteActionBookmark, null); pickState.ExecuteActionBookmark = null; }