S_Block









How do I use S_ Block
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: NetworkingPeer.cs Copy
459     private void LeftRoomCleanup()
460     {
461         bool wasInRoom = mRoomToGetInto != null;
462         // when leaving a room, we clean up depending on that room's settings.
463         bool autoCleanupSettingOfRoom = (this.mRoomToGetInto != null) ? this.mRoomToGetInto.autoCleanUp : PhotonNetwork.autoCleanUpPlayerObjects;
464
465         this.hasSwitchedMC = false;
466         this.mRoomToGetInto = null;
467         this.mActors = new Dictionary();
468         this.mPlayerListCopy = new PhotonPlayer[0];
469         this.mOtherPlayerListCopy = new PhotonPlayer[0];
470         this.mMasterClient = null;
471         this.allowedReceivingGroups = new HashSet();
472         this.blockSendingGroups = new HashSet();
473         this.mGameList = new Dictionary();
474         this.mGameListCopy = new RoomInfo[0];
475         this.isFetchingFriends = false;
476
477         this.ChangeLocalID(-1);
478
479         // Cleanup all network objects (all spawned PhotonViews, local and remote)
480         if (autoCleanupSettingOfRoom)
481         {
482             this.LocalCleanupAnythingInstantiated(true);
483             PhotonNetwork.manuallyAllocatedViewIds = new List(); // filled and easier to replace completely
484         }
485
486         if (wasInRoom)
487         {
488             SendMonoMessage(PhotonNetworkingMessage.OnLeftRoom);
489         }
490     }
File name: NetworkingPeer.cs Copy
2835     internal void RPC(PhotonView view, string methodName, PhotonPlayer player, bool encrypt, params object[] parameters)
2836     {
2837         if (this.blockSendingGroups.Contains(view.group))
2838         {
2839             return; // Block sending on this group
2840         }
2841
2842         if (view.viewID < 1) //TODO: check why 0 should be illegal
2843         {
2844             Debug.LogError("Illegal view ID:" + view.viewID + " method: " + methodName + " GO:" + view.gameObject.name);
2845         }
2846
2847         if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2848         {
2849             Debug.Log("Sending RPC \"" + methodName + "\" to player[" + player + "]");
2850         }
2851
2852
2853         //ts: changed RPCs to a one-level hashtable as described in internal.txt
2854         Hashtable rpcEvent = new Hashtable();
2855         rpcEvent[(byte)0] = (int)view.viewID; // LIMITS PHOTONVIEWS&PLAYERS
2856         if (view.prefix > 0)
2857         {
2858             rpcEvent[(byte)1] = (short)view.prefix;
2859         }
2860         rpcEvent[(byte)2] = this.ServerTimeInMilliSeconds;
2861
2862         // send name or shortcut (if available)
2863         int shortcut = 0;
2864         if (rpcShortcuts.TryGetValue(methodName, out shortcut))
2865         {
2866             rpcEvent[(byte)5] = (byte)shortcut; // LIMITS RPC COUNT
2867         }
2868         else
2869         {
2870             rpcEvent[(byte)3] = methodName;
2871         }
2872
2873         if (parameters != null && parameters.Length > 0)
2874         {
2875             rpcEvent[(byte) 4] = (object[]) parameters;
2876         }
2877
2878         if (this.mLocalActor == player)
2879         {
2880             this.ExecuteRPC(rpcEvent, player);
2881         }
2882         else
2883         {
2884             RaiseEventOptions options = new RaiseEventOptions() { TargetActors = new int[] { player.ID }, Encrypt = encrypt };
2885             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2886         }
2887     }
File name: NetworkingPeer.cs Copy
2890     /// (byte)0 -> (int) ViewId (combined from actorNr and actor-unique-id)
2891     /// (byte)1 -> (short) prefix (level)
2895     /// (byte)5 -> (byte) method shortcut (alternative to name)
2899     internal void RPC(PhotonView view, string methodName, PhotonTargets target, bool encrypt, params object[] parameters)
2900     {
2901         if (this.blockSendingGroups.Contains(view.group))
2902         {
2903             return; // Block sending on this group
2904         }
2905
2906         if (view.viewID < 1)
2907         {
2908             Debug.LogError("Illegal view ID:" + view.viewID + " method: " + methodName + " GO:" + view.gameObject.name);
2909         }
2910
2911         if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2912             Debug.Log("Sending RPC \"" + methodName + "\" to " + target);
2913
2914
2915         //ts: changed RPCs to a one-level hashtable as described in internal.txt
2916         Hashtable rpcEvent = new Hashtable();
2917         rpcEvent[(byte)0] = (int)view.viewID; // LIMITS NETWORKVIEWS&PLAYERS
2918         if (view.prefix > 0)
2919         {
2920             rpcEvent[(byte)1] = (short)view.prefix;
2921         }
2922         rpcEvent[(byte)2] = this.ServerTimeInMilliSeconds;
2923
2924
2925         // send name or shortcut (if available)
2926         int shortcut = 0;
2927         if (rpcShortcuts.TryGetValue(methodName, out shortcut))
2928         {
2929             rpcEvent[(byte)5] = (byte)shortcut; // LIMITS RPC COUNT
2930         }
2931         else
2932         {
2933             rpcEvent[(byte)3] = methodName;
2934         }
2935
2936         if (parameters != null && parameters.Length > 0)
2937         {
2938             rpcEvent[(byte)4] = (object[])parameters;
2939         }
2940
2941         // Check scoping
2942         if (target == PhotonTargets.All)
2943         {
2944             RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Encrypt = encrypt };
2945             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2946
2947             // Execute local
2948             this.ExecuteRPC(rpcEvent, this.mLocalActor);
2949         }
2950         else if (target == PhotonTargets.Others)
2951         {
2952             RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Encrypt = encrypt };
2953             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2954         }
2955         else if (target == PhotonTargets.AllBuffered)
2956         {
2957             RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache, Encrypt = encrypt };
2958             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2959
2960             // Execute local
2961             this.ExecuteRPC(rpcEvent, this.mLocalActor);
2962         }
2963         else if (target == PhotonTargets.OthersBuffered)
2964         {
2965             RaiseEventOptions options = new RaiseEventOptions() { CachingOption = EventCaching.AddToRoomCache, Encrypt = encrypt };
2966             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2967         }
2968         else if (target == PhotonTargets.MasterClient)
2969         {
2970             if (this.mMasterClient == this.mLocalActor)
2971             {
2972                 this.ExecuteRPC(rpcEvent, this.mLocalActor);
2973             }
2974             else
2975             {
2976                 RaiseEventOptions options = new RaiseEventOptions() { Receivers = ReceiverGroup.MasterClient, Encrypt = encrypt };
2977                 this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2978             }
2979         }
2980         else if (target == PhotonTargets.AllViaServer)
2981         {
2982             RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Receivers = ReceiverGroup.All, Encrypt = encrypt };
2983             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2984             if (PhotonNetwork.offlineMode)
2985             {
2986                 this.ExecuteRPC(rpcEvent, this.mLocalActor);
2987             }
2988         }
2989         else if (target == PhotonTargets.AllBufferedViaServer)
2990         {
2991             RaiseEventOptions options = new RaiseEventOptions() { InterestGroup = (byte)view.group, Receivers = ReceiverGroup.All, CachingOption = EventCaching.AddToRoomCache, Encrypt = encrypt };
2992             this.OpRaiseEvent(PunEvent.RPC, rpcEvent, true, options);
2993             if (PhotonNetwork.offlineMode)
2994             {
2995                 this.ExecuteRPC(rpcEvent, this.mLocalActor);
2996             }
2997         }
2998         else
2999         {
3000             Debug.LogError("Unsupported target enum: " + target);
3001         }
3002     }
File name: NetworkingPeer.cs Copy
3083     public void SetSendingEnabled(int group, bool enabled)
3084     {
3085         if (!enabled)
3086         {
3087             this.blockSendingGroups.Add(group); // can be added to HashSet no matter if already in it
3088         }
3089         else
3090         {
3091             this.blockSendingGroups.Remove(group);
3092         }
3093     }
File name: NetworkingPeer.cs Copy
3096     public void SetSendingEnabled(int[] enableGroups, int[] disableGroups)
3097     {
3098         if(enableGroups!=null){
3099             foreach(int i in enableGroups){
3100                 if(this.blockSendingGroups.Contains(i))
3101                     this.blockSendingGroups.Remove(i);
3102             }
3103         }
3104         if(disableGroups!=null){
3105             foreach(int i in disableGroups){
3106                 if(!this.blockSendingGroups.Contains(i))
3107                     this.blockSendingGroups.Add(i);
3108             }
3109         }
3110     }
File name: NetworkingPeer.cs Copy
3147     public void RunViewUpdate()
3148     {
3149         if (!PhotonNetwork.connected || PhotonNetwork.offlineMode)
3150         {
3151             return;
3152         }
3153
3154         if (this.mActors == null ||
3155#if !PHOTON_DEVELOP
3156             this.mActors.Count <= 1
3157#endif
3158             )
3159         {
3160             return; // No need to send OnSerialize messages (these are never buffered anyway)
3161         }
3162
3163         dataPerGroupReliable.Clear();
3164         dataPerGroupUnreliable.Clear();
3165
3166         /* Format of the data hashtable:
3167          * Hasthable dataPergroup*
3168          * [(byte)0] = this.ServerTimeInMilliSeconds;
3169          * OPTIONAL: [(byte)1] = currentLevelPrefix;
3170          * + data
3171          */
3172
3173         foreach (KeyValuePair kvp in this.photonViewList)
3174         {
3175             PhotonView view = kvp.Value;
3176
3177             if (view.synchronization != ViewSynchronization.Off)
3178             {
3179                 // Fetch all sending photonViews
3180                 if (view.isMine)
3181                 {
3182                     #if UNITY_2_6_1 || UNITY_2_6 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
3183                     if (!view.gameObject.active)
3184                     {
3185                         continue; // Only on actives
3186                     }
3187                     #else
3188                     if (!view.gameObject.activeInHierarchy)
3189                     {
3190                         continue; // Only on actives
3191                     }
3192                     #endif
3193
3194                     if (this.blockSendingGroups.Contains(view.group))
3195                     {
3196                         continue; // Block sending on this group
3197                     }
3198
3199                     // Run it trough its OnSerialize
3200                     Hashtable evData = this.OnSerializeWrite(view);
3201                     if (evData == null)
3202                     {
3203                         continue;
3204                     }
3205
3206                     if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed || view.mixedModeIsReliable)
3207                     {
3208                         if (!evData.ContainsKey((byte)1) && !evData.ContainsKey((byte)2))
3209                         {
3210                             // Everything has been removed by compression, nothing to send
3211                         }
3212                         else
3213                         {
3214                             if (!dataPerGroupReliable.ContainsKey(view.group))
3215                             {
3216                                 dataPerGroupReliable[view.group] = new Hashtable();
3217                                 dataPerGroupReliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3218                                 if (currentLevelPrefix >= 0)
3219                                 {
3220                                     dataPerGroupReliable[view.group][(byte)1] = this.currentLevelPrefix;
3221                                 }
3222                             }
3223                             Hashtable groupHashtable = dataPerGroupReliable[view.group];
3224                             groupHashtable.Add((short)groupHashtable.Count, evData);
3225                         }
3226                     }
3227                     else
3228                     {
3229                         if (!dataPerGroupUnreliable.ContainsKey(view.group))
3230                         {
3231                             dataPerGroupUnreliable[view.group] = new Hashtable();
3232                             dataPerGroupUnreliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3233                             if (currentLevelPrefix >= 0)
3234                             {
3235                                 dataPerGroupUnreliable[view.group][(byte)1] = this.currentLevelPrefix;
3236                             }
3237                         }
3238                         Hashtable groupHashtable = dataPerGroupUnreliable[view.group];
3239                         groupHashtable.Add((short)groupHashtable.Count, evData);
3240                     }
3241                 }
3242                 else
3243                 {
3244                     // Debug.Log(" NO OBS on " + view.name + " " + view.owner);
3245                 }
3246             }
3247             else
3248             {
3249             }
3250         }
3251
3252         //Send the messages: every group is send in it's own message and unreliable and reliable are split as well
3253         RaiseEventOptions options = new RaiseEventOptions();
3254
3255#if PHOTON_DEVELOP
3256         options.Receivers = ReceiverGroup.All;
3257#endif
3258
3259         foreach (KeyValuePair kvp in dataPerGroupReliable)
3260         {
3261             options.InterestGroup = (byte)kvp.Key;
3262             this.OpRaiseEvent(PunEvent.SendSerializeReliable, kvp.Value, true, options);
3263         }
3264         foreach (KeyValuePair kvp in dataPerGroupUnreliable)
3265         {
3266             options.InterestGroup = (byte)kvp.Key;
3267             this.OpRaiseEvent(PunEvent.SendSerialize, kvp.Value, false, options);
3268         }
3269     }
File name: BlockScript.cs Copy
42  void Update () {
43
44   if (moveStartTime >= 0F) {
45    float percentComplete = (Time.time - this.moveStartTime) / this.moveDuration;
46    if(this.blockNumber > -1) {
47     transform.position = Vector3.Lerp(this.originalPosition, this.moveNewPosition, percentComplete);
48    }
49    if (percentComplete >= 1F) {
50     this.moveStartTime = -1F;
51     this.setBlockNumber(this.moveNewBlockNumber);
52     transform.position = this.originalPosition;
53    }
54   }
55
56   if (this.rotationTotal >= 0F) {
57    float rotateBy = 90 * Time.deltaTime / this.moveDuration;
58    Vector3 rotationPoint = new Vector3 (3f, 4f, 3f);
59    transform.RotateAround(rotationPoint, this.rotateDirection, rotateBy);
60    this.rotationTotal += rotateBy;
61
62    if(rotationTotal >= 90) {
63     Debug.Log (rotationTotal);
64     this.rotationTotal = -1F;
65     transform.position = this.originalPosition;
66     transform.rotation = new Quaternion(0,0,0,1);
67     this.setBlockNumber(rotateNewBlockNumber);
68    }
69   }
70  }
File name: BlockScript.cs Copy
94  public void setBlockNumber(int blockNumber) {
95   this.blockNumber = blockNumber;
96   TextMesh textMesh = this.GetComponentInChildren();
97   Material blockTextMaterial = gameObject.transform.Find ("BlockText").gameObject.GetComponent().material;
98   MeshRenderer cube = gameObject.GetComponentInChildren();
99   Color cubeColor = cube.GetComponent().material.color;
100
101   //block doesn't exits
102   if(blockNumber == -2) {
103    cube.GetComponent().enabled = false;
104    textMesh.text = "";
105   }
106   //block is empty
107   else if (blockNumber == -1 ) {
108    cube.GetComponent().enabled = false;
109    cube.GetComponent().material.color = new Color(1, 1, 1, 0.2f);
110    textMesh.text = "";
111   }
112   //block has a value
113   else {
114    cube.GetComponent().enabled = true;
115    cube.material.color = this.getColor (blockNumber);
116    blockTextMaterial.SetColor ("_Color", new Color(1,1,1));
117    if(blockNumber == 0) blockTextMaterial.SetColor ("_Color", new Color(0.8f,0.8f,1));
118    textMesh.text = blockNumber.ToString();
119    transform.position = this.originalPosition;
120   }
121
122  }
File name: GameControllerScript.cs Copy
48  void Start (){
49
50   int x;
51   int y;
52   int z;
53   int axis;
54   yOffset = 1F;
55   Transform blockInstance;
56   BlockScript blockScript;
57   ConnectorScript connectorScript;
58   Transform connectorInstance;
59   TextMesh textMesh;
60
61   this.gameView = "menu";
62   this.options = this.gameObject.GetComponent ("OptionsScript") as OptionsScript;
63   this.timer = this.gameObject.GetComponent ("TimerScript") as TimerScript;
64   this.sizeGUI();
65
66   this.options.InitOptions();
67
68   //setup audio sources
69
70   AudioSource[] audioSources = GetComponents();
71   this.swipeAudioSource = audioSources[0];
72   this.collideAudioSource = audioSources[1];
73   this.collideAudioSource.clip = this.collideSound;
74
75   //instantiate the blocks and connectors and position them
76   for (x = 0; x <= 2; x++) {
77    for (y = 0; y <= 2; y++) {
78     for (z = 0; z <= 2; z++) {
79      //instantiate the block
80      blockInstance = Instantiate (block, new Vector3(x * this.scale, y * this.scale + this.yOffset, z * this.scale), Quaternion.identity) as Transform;
81      this.blocks[x,y,z] = blockInstance;
82      blockScript = blockInstance.gameObject.GetComponent("BlockScript") as BlockScript;
83      blockScript.Initialize(x,y,z,this);
84     }
85    }
86   }
87
88   // instantiate the connectors
89   for (x = 0; x <= 2; x++) {
90    for (y = 0; y <= 2; y++) {
91     for (z = 0; z <= 2; z++) {
92      //instantiate the x connector
93      connectorInstance = Instantiate (connector) as Transform;
94      connectorScript = connectorInstance.gameObject.GetComponent("ConnectorScript") as ConnectorScript;
95      connectorScript.Initialize(x,y,z,"x", this);
96      this.connectors[x,y,z,0] = connectorInstance;
97
98      //instantiate the y connector
99      connectorInstance = Instantiate (connector) as Transform;
100      connectorScript = connectorInstance.gameObject.GetComponent("ConnectorScript") as ConnectorScript;
101      connectorScript.Initialize(x,y,z,"y", this);
102      this.connectors[x,y,z,1] = connectorInstance;
103
104      //instantiate the z connector
105      connectorInstance = Instantiate (connector) as Transform;
106      connectorScript = connectorInstance.gameObject.GetComponent("ConnectorScript") as ConnectorScript;
107      connectorScript.Initialize(x,y,z,"z", this);
108      this.connectors[x,y,z,2] = connectorInstance;
109     }
110    }
111   }
112
113   //instantiate the move blocks
114   if (PlayerPrefs.HasKey ("game_status")) {
115    this.loadSavedGame();
116   }
117   else {
118    this.restart ();
119   }
120  }
File name: GameControllerScript.cs Copy
122  void setBlockNumber ( Transform blockInstance , int blockNumber ){
123   BlockScript blockScript;
124   blockScript = blockInstance.gameObject.GetComponent("BlockScript") as BlockScript;
125   blockScript.setBlockNumber(blockNumber);
126  }

S_Block 113 lượt xem

Gõ tìm kiếm nhanh...